在不同的包中有两个同名的实体 [英] Two entities with the same name in differents packages

查看:123
本文介绍了在不同的包中有两个同名的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我有两个具有相同名称的实体(但在不同的包中),导致一个异常:

I have two entities with the same name (but in differents packages) in my project, that cause an exception :

Use of the same entity name twice: MyEntity 

duplicate import: MyEntity refers to both packageOne.MyEntity and packageTwo.MyEntity (try using auto-import="false")

我尝试将属性 auto-import 设置为 false 在我的 persistence.xml 中,但它不会改变任何内容:

I tried to set the property auto-import to false in my persistence.xml, but it doesn't change anything :

<property name="hibernate.auto-import"  value="false"/>

是否有其他解决方案,而不是在实体注释中添加名称

Is there another solution than add a name in the Entity annotation

@Entity(name="MyEntity_One")
@Entity(name="MyEntity_Two")

推荐答案

确定您没有收到编译时间错误,您必须遇到的部署错误。问题在于,在部署之前将其打包成耳朵/战争时,这两个类都会到达服务器。虽然任何JPA应用程序容器都不知道要调用哪个类,因此它会引发异常。

Am sure you are not getting a compile time error, its deployment error that you must be encountering. the problem is when you package then into an ear/war before deploying, both the class come to the server. Whilst any JPA application the container does not know which class to invoke, thus it throws an exception

您是不可能扩展一个类并携带您的操作或您可以在另一个类中创建一个类的实例,并在它们之间添加一对一映射。

Is it not possible for you to extend one class and carry your operations or you can create an instance of one class in another and add a one-to-one mapping between them.

这篇关于在不同的包中有两个同名的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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