Websphere:JPA:java.lang.IllegalArgumentException:对象:实体不是已知的实体类型
我正在尝试使用 Eclipselink 作为 IBM Websphere 7.0.0.9 上的 JPA 层来部署应用程序。在尝试执行任何 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 这些异常的原因可能是什么?
I'm trying to deploy an app using Eclipselink as my JPA Layer on IBM Websphere 7.0.0.9. While trying to do any CRUD operations, i get the following exception:
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
Another stack trace i see is :
Caused by: java.lang.ClassCastException: Entity incompatible with Entity at o.u.d.dao.jpa.converter.impl.EntityBeanConvertorImpl.convertToModel(EntityBeanConvertorImpl.java:143) ... 223 more
My persistence.xml looks like:
<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>
My application context file looks like:
<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>
Our VM is started with the -javaagent parameter specified and pointing to spring-agent.jar What could be the reason for these exceptions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的问题是没有适用于 Websphere 的 Spring LoadTimeWeaver。当您的应用程序尝试将 Web 层应用程序与 Spring 管理的 EM 结合起来,同时使用 InstrumentationLoadTimeWeaver 类时,会产生异常结果。 EclipseLink 支持在所有符合 JPA 2 的容器中编织,但在这种情况下,Spring 充当中介并干扰编织。
在 Spring 拥有适用于 Websphere 的 LoadTimeWeaver 之前,您将需要删除 InstrumentationLoadTimeWeaver 并将 EclipseLink persistence.xml 属性“eclipselink.weaving”设置为 false 或使用静态编织器。
The issue here is there is no Spring LoadTimeWeaver for Websphere. When your application attempts to combine a Web-Tier application with the Spring managed EM while using the InstrumentationLoadTimeWeaver class cast exceptions result. EclipseLink supports weaving in all JPA 2 compliant containers but in this case Spring is acting as an intermediary and interfering with the weaving.
Until Spring has a LoadTimeWeaver for Websphere You will need to remove the InstrumentationLoadTimeWeaver and set the EclipseLink persistence.xml property "eclipselink.weaving" to false or use the Static weaver.