简体   繁体   English

原因:org.hibernate.AnnotationException:在不同包中的实体上使用两次相同的实体名称,但是名称相同

[英]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.

相关问题 获取org.hibernate.AnnotationException:未知实体名称:int - Getting org.hibernate.AnnotationException: Unknown entity name: int Junit-org.hibernate.AnnotationException引起的ExceptionInInitializerError - Junit - ExceptionInInitializerError caused by org.hibernate.AnnotationException 引起:org.hibernate.AnnotationException: @OneToOne 或 @ManyToOne on - Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on org.hibernate.AnnotationException:没有为实体指定标识符 - org.hibernate.AnnotationException: No identifier specified for entity 原因:java.lang.IllegalArgumentException:不是托管类型:&原因:org.hibernate.AnnotationException:未为实体指定标识符: - Caused by: java.lang.IllegalArgumentException: Not a managed type: & Caused by: org.hibernate.AnnotationException: No identifier specified for entity: 在春季使用Hibernate的困难:原因:org.hibernate.AnnotationException:使用@OneToMany或@ManyToMany定位未映射的类: - Difficulties to use Hibernate in a Spring: Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: 引起:org.hibernate.AnnotationException:mappedBy 引用了一个未知的目标实体属性 - Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property 无法构建Hibernate SessionFactory,由以下原因引起:org.hibernate.AnnotationException: - Unable to build Hibernate SessionFactory, Caused by: org.hibernate.AnnotationException: 由以下原因引起:org.hibernate.AnnotationException:XX上的@OneToOne或@ManyToOne引用了未知实体:YY - Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on XX references an unknown entity: YY org.hibernate.AnnotationException:@OneToOne on com.abc.dto.Test.name 引用了一个未知实体:com.abc.type.TestName - org.hibernate.AnnotationException:@OneToOne on com.abc.dto.Test.name references an unknown entity: com.abc.type.TestName
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM