[英]Caused by: org.hibernate.AnnotationException: Use of the same entity name twice on entities in different package but same name
I have two Entities with the same name, but in different package. 我有两个名称相同,但包装不同的实体。 For me it is obvious that should work. 对我来说,显然应该可行。 There is no duplicated name for entities. 实体没有重复的名称。
But I am getting an error: 但我收到一个错误:
Caused by: org.hibernate.AnnotationException: Use of the same entity name twice: Variant
I found solution, that tells me to use string value as Parameter for name attribute of @Entity
annotation, fe: 我找到了解决方案,告诉我将字符串值用作@Entity
批注fe的name属性的参数:
@Entity(name="legal_Variant")
But I don't like to use Strings in code. 但是我不喜欢在代码中使用字符串。 Can it be done other way? 可以通过其他方式完成吗? Fe using java reflection, or configuring somehow JPA
to use whole name (with package name)? Fe使用Java反射,还是配置JPA
以使用全名(带有包名)?
For me it is quite strange. 对我来说,这很奇怪。 I thought that JPA
takes care of package name also. 我以为JPA
也照顾包裹名称。
My classes code: 我的课程代码:
package insurance.models.liability.hiv;
@Entity
@Table(name="lLiability_Part_Hiv_Var")
public class Variant extends GenericDictionary<Variant> {
}
package insurance.models.liability.legal;
@Entity
@Table(name="liability_Part_Legal_Var")
public class Variant extends GenericDictionary<Variant> {}
It can be done in the mapping file: 可以在映射文件中完成:
<hibernate-mapping>
<import class="insurance.models.liability.legal.Variant" rename="Var1" />
</hibernate-mapping>
You can now use an HQL query such as 您现在可以使用HQL查询,例如
from Var1
Reference: Java Persistence with Hibernate (Chapter 4 pag.173/174) 参考: Java Persistence with Hibernate(第4章,页173/174)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.