How can we use JPA2 (Hibernate) objects as DTO between two webapps?

Hi guys We are working on Glassfish 3.0.1 and are using Hibernate 3.5.3. Our project setup is as follows:

frontend.war

common.jar

backend.war

We would like to add jpa2 annotated objects to common.jar so that the backend treats them as JPA2 entities, but the interface should only see them as POJO / DTO. We thought this could be achieved by adding persistence.xml to backend.war and does not have persistence.xml in the interface. This does not work after starting the backend and calling entityManager.getMetamodel (). GetEntities (), we get an empty list. All requests fail with exceptions: "Not an entity: com.example.model.OurEntity".

We tried both with beans.xml and without it in common.jar.

Any idea what we're doing wrong? Can this structure be used with JPA2?

+5
source share
1 answer

When annotated objects are not in the same file as persistence.xml, you need to add <jar-file>to persistence.xml. Depending on your setup, this might look like this:

<jar-file>lib/common.jar</jar-file>
+5
source

All Articles