I'm just starting out on the road to learning JavaEE5 and JPA. I've created a set of JPA entities (all in Eclipse 3.4 using the WTP's various JPA & JavaEE projects) and added them to an EAR file. Access to the JPA entities is via a set of session beans, packaged in an EJB jar and added to the same EAR. The EAR is then deployed to Apache Geronimo 2.1.
I'd then like to run the web UI from a WAR file running on another app server. The WAR includes the JPA entity jar so the entity beans can be used as DTOs via the session beans. However, when the WAR file is deployed, the web server (Geronimo 2.1 again) complains that the data source for the JPA entities is not defined. Which is reasonable as its part of the persistance.xml in the entities' jar file.
My question is: what's the best way of packaging the JPA entities so they can be used as JPA entities by the main app server, and as simple POJO DTOs by the web server? I'm guessing it involves separating persistance.xml from the entity beans. But that seems to put an end to using the nice JPA features in Eclipse.
>>complains that the data source for the JPA entities is not defined
Could you expand on that error?
Correct me if I'm wrong, but you reference a datasource in you jar file, but you then must physically go to the application server and set up the datasource. So, a datasource must be configured manually on your J2EE/JEE5 server, and the name of this configured datasource is referenced in the persistence file. So, I'm wondering if the problem is just that you have missed this step.
If you use a JNDI explorer or something, can you see and lookup the datasource successfully?
Joined: Jan 19, 2009
In theory I'd like to run the application across two application servers. One running the business logic (session beans & JPA entity beans), and the other running the web UI (JSF). The web part would request data from the business part via the session beans, the sessions beans returning the JPA entities back to the web UI as POJOs. Both the business and web parts are using Geronimo 2.1.
I've registered the data source in the business logic app server, which is the only part that should access the database. I understand that the JPA entities should be detached from the persistance manager when they are serialized over to the web UI. So the web UI server should not need the data source to be registered.
I think my problem is the way I've got the JPA entities packaged. They were created in an Eclipse WTP2 JPA project, so have the entities and the persistance deployment descriptors packaged together in a single jar file. I've then included this jar file in both an ear file, which gets deployed to the business logic app server, and a war file, which gets deployed to the web UI app server. When I try and deploy the war it gets rejected because of the lack of a data source on the web UI app server.
I hope that makes my setup a bit clearer. Sorry it's such a long-winded explanation.