我们如何在两个webapps之间使用JPA2(Hibernate)实体作为DTO? [英] How can we use JPA2 (Hibernate) entities as DTO's between two webapps?

查看:183
本文介绍了我们如何在两个webapps之间使用JPA2(Hibernate)实体作为DTO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家
我们在Glassfish 3.0.1上运行并使用Hibernate 3.5.3。
我们的项目设置如下所示:



frontend.war



common.jar



backend.war

我们想将我们的jpa2注释实体放在common.jar中,使后端将它们视为JPA2实体,但前端应仅将它们看作POJO / DTO的实体。我们认为这可以通过将persistence.xml放在
backend.war中并且在前端没有persistence.xml来完成。这不起作用,在启动后端并调用entityManager.getMetamodel()。getEntities()之后,我们得到一个空列表。所有查询都会以exeptions失败:不是实体:com.example.model.OurEntity。

我们已经在common.jar中尝试了有和没有beans.xml。



任何想法我们做错了什么?是否可以在JPA2中使用此结构?

解决方案

当注释实体与<$ c $不在同一个文件中时c> persistence.xml ,您需要将< jar-file> 添加到 persistence.xml 。根据您的设置,它可以如下所示:

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


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?

解决方案

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>

这篇关于我们如何在两个webapps之间使用JPA2(Hibernate)实体作为DTO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆