hibernate几个 OneToMany.异常总结

本文总结了使用Hibernate进行一对多关系映射时常见的三个错误及其解决方案,包括配置问题、映射属性设置不当及HQL查询引发的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

hibernate几个 OneToMany.错误总结
http://alinazh.blog.51cto.com/5459270/1279354
错误一
org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined: com.hibernate.SubStation.bays

错误解决方法
org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined: org.svse.org.model.Order.orderItems
在用annotation做数据库映射一对多和多对一的时候要注意:因为这个问题只有在用annotation的时候才有,用xml文件的时候就没有在一对多关系映射中
一的一方直接写Set就可以不用指定相应的元素类型!!
请 检查orderItems这个属性是否使用了泛型,如:Set<OrderItem>. 
如 果未使用泛型,请在OneToMany注释中使用targetEntity指定元素的类型
错误二
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.hibernate.Bay.group in com.hibernate.SubStation.bays
错误解决方法
在用annotation做数据库映射一对多和多对一的时候要注意:
@OneToMany(mappedBy = "news_type", cascade = CascadeType.ALL,fetch = FetchType.LAZY)  这里的mappedBy 要对应
@ManyToOne
@JoinColumn(name="news_type", nullable=true, insertable = true, updatable = true) 
private NewsType newsType;的NewsType对象名,也就是newsType而不是字段名news_type。
错误三
node to traverse cannot be null!
出现这种问题是因为HQL语句出现问题,引起内部查询对象为空,无法处理为空值引起的。解决方法,检查HQL语句(尤其是关键字)。

 

转自:http://www.imooo.com/ruanjiangongcheng/software-architecture-design/35068.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值