Websphere:JPA:java.lang.IllegalArgumentException:Object:Entity不是已知的实体类型

时间:2010-07-07 07:53:51

标签: spring jpa websphere

我正在尝试使用Eclipselink将应用程序部署为IBM Websphere 7.0.0.9上的JPA Layer。在尝试执行任何CRUD操作时,我得到以下异常:

Caused by: java.lang.IllegalArgumentException: Object: Entity is not a known entity type.
 at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4199)
 at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:380)
 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.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:358)
 at $Proxy93.persist(Unknown Source)
 ... 89 more

我看到的另一个堆栈跟踪是:

Caused by: java.lang.ClassCastException: Entity incompatible with Entity
    at o.u.d.dao.jpa.converter.impl.EntityBeanConvertorImpl.convertToModel(EntityBeanConvertorImpl.java:143)
    ... 223 more

我的persistence.xml看起来像:

     <persistence-unit name="ds" transaction-type="JTA">   <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>      <jta-data-source>dsjta</jta-data-source>   <class>Entity</class>      <exclude-unlisted-classes>true</exclude-unlisted-classes>     <properties>    <property name="eclipselink.target-server" value="WebSphere_7" />    <property name="eclipselink.logging.level" value="OFF" />    <property name="eclipselink.ddl-generation" value="none" />    <property name="eclipselink.ddl-generation.output-mode" value="database" />    </properties>  </persistence-unit>

我的应用程序上下文文件如下所示:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">    <property name="persistenceUnitName" value="ds"/>  <property name="dataSource" ref="dataSource"/>  <property name="jpaVendorAdapter">   <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">    <property name="showSql" value="false"/>    <property name="generateDdl" value="false"/>   </bean>  </property>  <property name="loadTimeWeaver">   <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>  </property>   </bean>

我们的VM以指定的-javaagent参数启动并指向spring-agent.jar这些异常可能是什么原因?

1 个答案:

答案 0 :(得分:1)

这里的问题是没有用于Websphere的Spring LoadTimeWeaver。当您的应用程序尝试将Web层应用程序与Spring托管EM结合使用时,使用InstrumentationLoadTimeWeaver类转换异常结果。 EclipseLink支持在所有兼容JPA 2的容器中编织,但在这种情况下,Spring充当中介并干扰编织。

在Spring有一个用于Websphere的LoadTimeWeaver之前您需要删除InstrumentationLoadTimeWeaver并将EclipseLink persistence.xml属性“eclipselink.weaving”设置为false或使用Static weaver。