It's not a secret anymore!*
The moose likes Object Relational Mapping and the fly likes Best practice for packagine JPA entities for use in client app server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Best practice for packagine JPA entities for use in client app server" Watch "Best practice for packagine JPA entities for use in client app server" New topic
Author

Best practice for packagine JPA entities for use in client app server

Mark Crompton
Greenhorn

Joined: Jan 19, 2009
Posts: 2
Hi,

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.

Any suggestions would be gratefully received.

Many thanks,
Mark
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

>>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?

-Cameron McKenzie


Mark Crompton
Greenhorn

Joined: Jan 19, 2009
Posts: 2
Hi Cameron,

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.

Cheers,
Mark

 
wood burning stoves
 
subject: Best practice for packagine JPA entities for use in client app server