org.hibernate.AnnotationException:集合既没有泛型类型,也没有OneToMany.targetEntity() [英] org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity()
问题描述
我使用 Hibernate Tools 来生成我的Hibernate POJO映射。
不幸的是,由Hibernate工具生成的代码似乎不起作用,我得到了异常
org .hibernate.AnnotationException:Collection既没有泛型类型,也没有OneToMany.targetEntity()
生成异常的代码部分是
/ **
*由hbm2java生成的ClassFlag
* /
@Entity
@Table(name = class_flag,catalog =incbszdb)
public class ClassFlag implements java.io.Serializable {
...
/ * HERE * /
private Set classFlagI18ns = new HashSet(0);
/ * HERE * /
public void setClassFlagI18ns(Set classFlagI18ns){
this.classFlagI18ns = classFlagI18ns;
}
}
根据这篇文章
和这篇文章
< a href =http://www.mkyong.com/hibernate/hibernate-error-collection-has-neither-generic-type-or-onetomany-targetentity/ =noreferrer> http://www.mkyong .com / hibernate / hibernate-error-collection-have-none-generic-type-onetomany-targetentity /
你必须更改生成的Hibernates手动编码。
这是我想避免的一件事。任何想法可能是什么问题?
问候
JS
只需检查使用Java 5语法 ,如附件屏幕截图所示,
Hibernate Tools为集合生成正确的通用类型。
I used Hibernate Tools to generate my Hibernate POJO mapping.
Unfortunately the code generated by Hibernate tools seems not to work, I get the exception
org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity()
The code parts that generate the exception are
/**
* ClassFlag generated by hbm2java
*/
@Entity
@Table(name = "class_flag", catalog = "incbszdb")
public class ClassFlag implements java.io.Serializable {
....
/* HERE */
private Set classFlagI18ns = new HashSet(0);
/* HERE */
public void setClassFlagI18ns(Set classFlagI18ns) {
this.classFlagI18ns = classFlagI18ns;
}
}
According to this post
and this post
You have to change Hibernates generated code by yourself by hand.
This is one thing I want to avoid. Any ideas what could be the problem?
Regards
JS
I have found a solution for me that works.
Simply check "Use Java 5 Syntax" as depicted in the attached Screenshot and Hibernate Tools generate the correct generic types for collections.
这篇关于org.hibernate.AnnotationException:集合既没有泛型类型,也没有OneToMany.targetEntity()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!