Marc Enschede
Marc Enschede

Reputation: 898

I want to share a JPA annotated entity model over a several JEE6 WEB projects

I want to share an entity model, annotated with JPA, over a several JEE6 WEB projects. The entities are annotated like this:

@Entity
public class Contract implements Serializable {

I created a maven project with only annotated entity classes, the entity project.

In the client JEE6 WEB project I created a dependency on this entity project. The JEE6 project is able to compile, but when executing on a Glassfish application server there is a runtime error. The class is not recognized as a Entity class.

Caused by: java.lang.IllegalArgumentException: Object: nl.marcenschede.modules.Contract[ id=null ] is not a known entity type.

What to do for an imported class to be recognized as an entity project?

Upvotes: 5

Views: 2750

Answers (2)

Gab
Gab

Reputation: 8332

You just need to package the persistence unit classes inside a jar with a META-INF folder containing the persistence.xml file listing all entities classes.

The resulting jar must be then included in the WEB-INF/lib directory of your web-apps war files.

See http://docs.oracle.com/javaee/6/tutorial/doc/bnbqw.html#bnbrj

Upvotes: 0

Eugene Loy
Eugene Loy

Reputation: 12426

Have a look here for working example of how to do this.

Upvotes: 1

Related Questions