开发者

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

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 pe开发者_如何学Gorsistence.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?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜