How can we use JPA2 (Hibernate) entities as DTO's between two webapps?

删除回忆录丶 提交于 2020-01-23 07:08:26

问题


Hi guys We're running on Glassfish 3.0.1 and using Hibernate 3.5.3. Our project setup looks like this:

frontend.war

common.jar

backend.war

We would like to put our jpa2 annotated entities in common.jar in such a way that the backend treats these as JPA2 entities, but the frontend should only see these as POJO's/DTO's. We thought this could be accomplished bu putting persistence.xml in backend.war and having no persistence.xml in the frontend. This doesn't work, after starting up the backend and calling entityManager.getMetamodel().getEntities(), we get an empty list. All queries fail with exeptions: "Not an entity: com.example.model.OurEntity".

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

Any idea what we are doing wrong? Is it possible to use this structure with JPA2?


回答1:


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

<jar-file>lib/common.jar</jar-file>


来源:https://stackoverflow.com/questions/5064734/how-can-we-use-jpa2-hibernate-entities-as-dtos-between-two-webapps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!