小编Ste*_*eve的帖子

JPA认为我正在删除一个分离的对象

我有一个DAO,我曾经使用JPA加载和保存我的域对象.我终于设法使交易工作正常,现在我又遇到了另一个问题.

在我的测试用例中,我调用我的DAO来加载具有给定id的域对象,检查它是否已加载,然后调用相同的DAO来删除刚刚加载的对象.当我这样做时,我得到以下内容:

java.lang.IllegalArgumentException: Removing a detached instance mil.navy.ndms.conops.common.model.impl.jpa.Group#10
 at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:45)
 at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:108)
 at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
 at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:794)
 at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:772)
 at org.hibernate.ejb.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:253)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
 at java.lang.reflect.Method.invoke(Method.java:600)
 at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:180)
 at $Proxy27.remove(Unknown Source)
 at mil.navy.ndms.conops.common.dao.impl.jpa.GroupDao.delete(GroupDao.java:499)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
 at java.lang.reflect.Method.invoke(Method.java:600)
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
 at $Proxy28.delete(Unknown Source)
 at mil.navy.ndms.conops.common.dao.impl.jpa.GroupDaoTest.testGroupDaoSave(GroupDaoTest.java:89)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
 at java.lang.reflect.Method.invoke(Method.java:600)
 at junit.framework.TestCase.runTest(TestCase.java:164)
 at junit.framework.TestCase.runBare(TestCase.java:130)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at …
Run Code Online (Sandbox Code Playgroud)

java spring entity jpa

41
推荐指数
4
解决办法
6万
查看次数

Iphone:可以隐藏TabBar吗?(iOS 8之前)

我有一个使用a UITabBarController在模式之间切换的应用程序.在某种模式下,我想隐藏标签栏,直到该模式的步骤完成.请注意,我没有使用导航控制器,所以我无法使用setHidesBottomBarWhenPushed导航控制器上的方法来隐藏标签栏.

在iOS 8之前,当我尝试使用以下命令隐藏tarbar时:

self.tabBarController.tabBar.hidden = YES
Run Code Online (Sandbox Code Playgroud)

标签栏消失,但它在屏幕底部留下了一个50像素的空白区域,标签栏曾经是.我似乎无法弄清楚如何填补该区域.用户界面中该区域中的任何内容都被剪切,无法看到.

任何想法,如果这是可能的?我真的很想远离导航控制器.

iphone objective-c uitabbarcontroller ios

34
推荐指数
4
解决办法
3万
查看次数

在Jersey服务中使用JSON对象

我一直在谷歌搜索我的屁股试图找到如何做到这一点:我有一个泽西REST服务.调用REST服务的请求包含JSON对象.我的问题是,从Jersey POST方法实现,我如何才能访问HTTP请求正文中的JSON?

任何提示,技巧,示例代码的指针将不胜感激.

谢谢...

--Steve

json jersey

33
推荐指数
4
解决办法
6万
查看次数

Spring @Transactional没有创建所需的事务

好的,所以我终于屈服于同伴压力并开始在我的网络应用程序中使用Spring: - )...

所以我试图让事务处理工作起作用,而我似乎无法得到它.

我的Spring配置如下所示:


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx.xsd">

    <bean id="groupDao" class="mil.navy.ndms.conops.common.dao.impl.jpa.GroupDao" lazy-init="true">
        <property name="entityManagerFactory" ><ref bean="entityManagerFactory"/></property>
    </bean>

 <!-- enables interpretation of the @Required annotation to ensure that dependency injection actually occures -->
  <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>  

  <!-- enables interpretation of the @PersistenceUnit/@PersistenceContext annotations providing convenient
       access to EntityManagerFactory/EntityManager -->
  <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

  <!-- uses the persistence unit defined in the META-INF/persistence.xml JPA configuration file -->
  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="CONOPS_PU" /> 
  </bean>

  <!-- …
Run Code Online (Sandbox Code Playgroud)

spring jpa transactional

14
推荐指数
2
解决办法
4万
查看次数

如何在Objectify中对答案进行排序?

我目前正在使用Objectify 3.1构建一个部署到GAE的应用程序.尝试使用order()子句进行查询时,我得到了奇怪的结果.

我的域名:


public class InvoiceLineItem
{
    private int units;

    private BigDecimal unitCost;
    private BigDecimal extendedCost;

    private String description;

    @Parent Key<Invoice> invoice;
}
Run Code Online (Sandbox Code Playgroud)

我试图使用以下内容收集与给定发票关联的所有InvoiceLineItem:

ofy ().query (InvoiceLineItem.class).ancestor (invoiceKey).list ( );
Run Code Online (Sandbox Code Playgroud)

在我的测试用例中,这很好用,按预期返回2行.

但是,当我尝试向上述查询添加排序顺序时,如下所示:

ofy ().query (InvoiceLineItem.class).ancestor (invoiceKey).order ("+description").list ();
Run Code Online (Sandbox Code Playgroud)

我总是得到0结果.我已经尝试改变顺序方向,它的排序字段,查询中order()子句的位置,都没有效果.任何人都能看到我在这里做错的事吗?

谢谢...

google-app-engine objectify google-cloud-datastore

13
推荐指数
1
解决办法
7780
查看次数

Spring/Junit/JPA的依赖注入

我正在尝试使用Spring 2.5.6和JUnit 4.8.1为我的JPA DAO类创建JUnit测试.

我的测试用例如下:


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:config/jpaDaoTestsConfig.xml"} )
public class MenuItem_Junit4_JPATest extends BaseJPATestCase {

    private ApplicationContext context;
    private InputStream dataInputStream;
    private IDataSet dataSet;

    @Resource
    private IMenuItemDao menuItemDao;

    @Test
    public void testFindAll() throws Exception {
        assertEquals(272, menuItemDao.findAll().size());
    }

    ... Other test methods ommitted for brevity ...
}
Run Code Online (Sandbox Code Playgroud)

我在jpaDaoTestsConfig.xml中有以下内容:


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx.xsd">

  <!-- uses the persistence unit defined in the META-INF/persistence.xml JPA configuration file -->
  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="CONOPS_PU" /> 
  </bean> …
Run Code Online (Sandbox Code Playgroud)

junit spring jpa

10
推荐指数
1
解决办法
3万
查看次数

在日期字段上使用max的JPQL查询

我需要查询以从一组记录中查找具有最新日期的记录.我尝试了很多东西,最近的东西是这样的:

select msg, msg.createdDate from ImportedMessage msg where msg.siteId = ?1 and msg.createdDate = max(msg.createdDate) group by msg.createdDate

不幸的是,我尝试的一切都产生了某种错误.我似乎得到的最大错误是:

Caused by: java.sql.SQLException: Not in aggregate function or group by clause: 
org.hsqldb.Expression@688c688c in statement [select importedme0_.IMPORTED_MSG_ID as 
col_0_0_, importedme0_.CREATED_DATE as col_1_0_, max(importedme0_.CREATED_DATE) as 
col_2_0_, importedme0_.IMPORTED_MSG_ID as IMPORTED1_1_, importedme0_.CREATED_BY as
CREATED2_1_, importedme0_.CREATED_DATE as CREATED3_1_, importedme0_.UPDATED_BY as
UPDATED4_1_, importedme0_.UPDATED_DATE as UPDATED5_1_, importedme0_.IMPORT_TYPE as
IMPORT6_1_, importedme0_.MESSAGE as MESSAGE1_, importedme0_.PROCESSED_FLAG as
PROCESSED8_1_, importedme0_.SITE_ID as SITE9_1_ from IMPORTED_MSG importedme0_ where
importedme0_.SITE_ID=? and importedme0_.CREATED_DATE=max(importedme0_.CREATED_DATE) 
group by importedme0_.CREATED_DATE] …

jpa jpql

9
推荐指数
1
解决办法
2万
查看次数

如何让Hibernate调用我的自定义typedef?

我正在尝试定义一个CompositeUserType来处理我的JPA/Hibernate应用程序中的特定类型.我有一个名为ApplicationMessageType的CompositeUserType,用于处理我的映射.

根据我读过的内容,我应该能够在包含TypeDef的域层次结构中创建一个package-info.java类.我看起来像这样:

@TypeDefs({
    @TypeDef(
        defaultForType = ApplicationMessage.class,
        typeClass = ApplicationMessageType.class
    )
})
package mptstp.domain;

import mptstp.domain.messages.ApplicationMessage;

import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
Run Code Online (Sandbox Code Playgroud)

如果我理解正确,我正在使用DefaultDeType参数到TypeDef这一事实,无论何时我尝试保存或加载ApplicationMessage,都应该调用自定义类型代码.

我已经在ApplicationMessageType类中的每个方法上设置了断点,并且没有一个 被调用.

有谁知道我哪里出错了?代码编译,但似乎从未调用TypeDef注释来注册ApplicationMessageType.

任何指针将不胜感激......

谢谢

annotations hibernate typedef hibernate-annotations

7
推荐指数
1
解决办法
1万
查看次数

XStream:在我解析时折叠XML层次结构

我有一个XML文档(由Adobe XFA表单生成),其中包含如下数据:

<Position>
   <PositionBorder>
       <Title/>
       <StartDate/>
       <EndDate/>
   </PositionBorder>
</Position>
Run Code Online (Sandbox Code Playgroud)

由于此文件是在其他地方定义的,因此我无权更改我获得的XML格式.

在我的Java代码中,我创建了一个包含Title,Start和End Dates的Position类.

我的问题是,当我使用XStream来解析文件时,它需要一个PositionBorder类来保存标题和日期.我想基本上忽略边框并将所有字段放入Position类.

我真正想做的是使用convertAnother方法来转换position元素的子元素.我试图这样做但它失败了,因为我的PositionConverter被调用了PositionBorder(当我调用convertAnother时).

任何人都有任何线索如何处理解析时折叠XML的结构?

java xml parsing converter xstream

6
推荐指数
1
解决办法
2804
查看次数

从SQL文件生成数据字典的工具

好的,所以我被骗了为我工作的Oracle数据库做一些数据库设计.问题是,我不是一个数据库人:-).我目前正在使用Rational Application Developer(RAD)来对我的数据库模式进行建模.我理想的做法是生成一系列Word文档,其中包含来自我的数据库模式的信息(主要是表/列信息,约束和触发器作为Word文档中的表).

我似乎无法用RAD找到任何方法,所以我想知道是否有人知道可以采用SQL DDL脚本文件(包含架构的CREATE命令)的工具,并生成Word类型的报告?

任何指针都非常感激.

谢谢...

sql oracle database-schema

5
推荐指数
1
解决办法
7233
查看次数