|Re: JPA 2.0 non-jta-data-source issue [message #503774 is a reply to message #503226]
||Tue, 15 December 2009 17:14
| James Sutherland
Registered: July 2009
Location: Ottawa, Canada
I'm not familiar with the 6th Platform, but I assume the issue is how you have configured things.|
Since each bean has its own non-managed EntityManager, each EntityManager will have its own persistence context and transaction context. They will only be able to see each others changes after they commit (and possible refresh for updated objects as they may be already in the persistence context).
Are you calling commit()? If so, then how have you configure your persistence unit, are you using JTA or RESOURCE_LOCAL. If you are using JTA, you need to set the target-server in EclipseLink to integrate with your server's JTA implementation. You would also need to join a JTA transaction because you are using an application managed EntityManager.
In JEE the EntityManager is normally injected using @PersistenceContext and is JTA managed and accessed from SessionBean methods. You don't seem to be using JEE, so probably need to be managing your EntityManagers and transactions directly. Having singletons each with their own EntityManager seems to be a bad design, you should most likely hold an EntityManagerFactory and create and close an EntityManager per request, or per transaction.
James : Wiki : Book : Blog : Twitter
|Re: JPA 2.0 non-jta-data-source issue [message #504096 is a reply to message #503774]
||Thu, 17 December 2009 04:00
| No real name
Registered: December 2009
Thank you for your reply.
We are discussing the situation where each Singleton has its own EntityManager. You think it seems to be a bad design, I don't agree, but for the sake of the discussion lets stick to the point:
For a JTA data-source, all the entity managers operate over the same Persistence Context.
For a RESOURCE_LOCAL data-source, Eclipse-Link provides each entityManager with each its own persistence unit.
Sun Microsystem's official specification of JPA 2.0 : JSR 317 does not clearly specify that for a RESOURCE_LOCAL data-source, each entity manage must have its own persistence unit, nor does it clearly specify that all the entity managers should use the same persistence unit.
Now lets look at the persistence.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" ...>
<persistence-unit name="BShopPU1" transaction-type="RESOURCE_LOCAL">
Isn't it common sense that all RESOURCE_LOCAL entity managers operate over the same persistence unit?
Why should one create and close an EntityManager per request, or per transaction? Why the extra number of objects and operations?
J2EE version 6 has the official status of final draft, and it is also up to its providers to determine its specifications, just as J2EE 5's JPA 1.0 behaved differently depending on its provider.
Additionally to this discussion I found a bug in EclipseLink's implementation of JPA 2.0 API. Is this forum for bug report or can you point me to the official bug report page?
Powered by FUDForum
. Page generated in 0.01545 seconds