org.hibernate.AnnotationException:集合既没有泛型类型,也没有OneToMany.targetEntity() [英] org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity()

查看:208
本文介绍了org.hibernate.AnnotationException:集合既没有泛型类型,也没有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;
}

}

根据这篇文章



http://www.mkyong.com/hibernate/org-hibernate-annotationexception-collection-has-neither-generic-type-or-onetomany- targetentity / comment-page-1 /#comment-67404

和这篇文章



< 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.stack.imgur.com/Fz3OP.pngalt =在这里输入图片描述>


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

http://www.mkyong.com/hibernate/org-hibernate-annotationexception-collection-has-neither-generic-type-or-onetomany-targetentity/comment-page-1/#comment-67404

and this post

http://www.mkyong.com/hibernate/hibernate-error-collection-has-neither-generic-type-or-onetomany-targetentity/

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屋!

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