我可以检索实体,但无法保留 WebSphere 7 JPA
我正在处理一个在 NetBeans 中开发的应用程序。它使用单个实体,可以从数据库检索或保留新实体。它使用带有 EclipseLink 的 JPA 2.0。当部署在捆绑的 Glassfish 中时,它可以正常工作。但是,当部署到 WAS 7.0.0.9(已包含 JPA 2.0 补丁)时,我可以检索实体,但无法保留它们。
我在无状态 EJB 3.0 中保留的代码是:
public void create(MyEntity entity) {
getEntityManager().persist(entity);
}
我已将日志记录属性设置为 FINEST,因此我可以获得更多详细信息,
<property name="eclipselink.logging.level" value="FINEST"/>
但我在日志中得到的只是:
[EL Finer]: 2011-07-11 17:02:59.813--UnitOfWork(1634296169)--Thread(Thread[WebContainer : 9,5,main])--initialize identitymaps
[EL Finer]: 2011-07-11 17:02:59.815--ServerSession(833630640)--Thread(Thread[WebContainer : 9,5,main])--client acquired
[EL Finest]: 2011-07-11 17:02:59.815--UnitOfWork(137562163)--Thread(Thread[WebContainer : 9,5,main])--PERSIST operation called on: PU_TEST.
[EL Finer]: 2011-07-11 17:02:59.816--UnitOfWork(137562163)--Thread(Thread[WebContainer : 9,5,main])--initialize identitymaps
服务器日志也没有显示有关此的信息。有什么想法吗?
提前致谢。
解决方案: 这是工作的 persistence.xml 文件
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="fonacotCap" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/fonacotCap</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-server" value="WebSphere_7"/>
<property name="eclipselink.target-database" value="Informix"/>
<property name="eclipselink.weaving" value="true"/>**
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="eclipselink.logging.file" value="/opt/apps/libs/persistence.log"/>
</properties>
</persistence-unit> </persistence>
I am dealing with an application developed in NetBeans. It uses a single entity and can either retrieve from DB or persist new entities. It uses JPA 2.0 w/ EclipseLink. When deployed in bundled Glassfish, it works correctly. However, when deploying into WAS 7.0.0.9 (already includes the JPA 2.0 patch), I can retrieve entities, but I can't persist them.
My code to persist, within a Stateless EJB 3.0 is:
public void create(MyEntity entity) {
getEntityManager().persist(entity);
}
I've set the logging property to FINEST, so I can get more detail,
<property name="eclipselink.logging.level" value="FINEST"/>
but all I get in the log is:
[EL Finer]: 2011-07-11 17:02:59.813--UnitOfWork(1634296169)--Thread(Thread[WebContainer : 9,5,main])--initialize identitymaps
[EL Finer]: 2011-07-11 17:02:59.815--ServerSession(833630640)--Thread(Thread[WebContainer : 9,5,main])--client acquired
[EL Finest]: 2011-07-11 17:02:59.815--UnitOfWork(137562163)--Thread(Thread[WebContainer : 9,5,main])--PERSIST operation called on: PU_TEST.
[EL Finer]: 2011-07-11 17:02:59.816--UnitOfWork(137562163)--Thread(Thread[WebContainer : 9,5,main])--initialize identitymaps
The server logs show no info about this either. Any ideas?
Thanks in advance.
SOLUTION:
This is the working persistence.xml file
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="fonacotCap" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/fonacotCap</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-server" value="WebSphere_7"/>
<property name="eclipselink.target-database" value="Informix"/>
<property name="eclipselink.weaving" value="true"/>**
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="eclipselink.logging.file" value="/opt/apps/libs/persistence.log"/>
</properties>
</persistence-unit> </persistence>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否已将 eclipselink 配置为持久性提供程序?默认情况下,WAS 使用自己的持久性提供程序(它包装 OpenJPA)。
配置 WAS 持久性提供程序
Have you configured eclipselink as your persistence provider? By default WAS uses its own persistence provider (which wraps OpenJPA).
Configuring WAS Persistence Provider