(转)hibernate 注解的问题(异常)集合
1,問題:An AnnotationConfiguration instance is required to use <mapping class="vo.Student"/>
解答:錯誤:SessionFactory factory = new Configuration().configure().buildSessionFactory(); //這句是用映射文件為xml的
? ? ?? 正確:SessionFactory factory = new AnnotationConfiguration().configure().buildSessionFactory();//這句是用于注解的
? ? ??
2,問題:@OneToOne or @ManyToOne on vo.StuCour.student references an unknown entity: vo.Student
解答:錯誤原因(1):配置文件沒有添加映射
? ? ?? ?方法:加上配置:在hibernta.hfg.xml<mapping class="vo.Student"/>
? ? ?? ? ?錯誤原因(2):在實體類public class ClassName上面沒有加實體注解,
? ? ?? ?方法:加上注解:@Entity
? ? ?? ? ? ?? ? ? ?? ? ? ?? ? ? ?? ?@Table(name = "Student", catalog = "sms")
? ? ?? ? ? ?? ? ? ?? ? ? ?? ? ? ?? ?
3,問題:mappedBy reference an unknown target entity property: vo.StuCour.stuCours
? ?錯誤原因:在one-to-many注解配置: @OneToMany (mappedBy = "StuCour"),mappedBy指向的是要關(guān)聯(lián)的屬性,而不是要關(guān)聯(lián)的類,
? ? ?? ? ? ?? 如果這樣配置,hibernate則會找vo.StuCour類下面的stuCours屬性。但實際上沒有這個屬性,就會報上面的異常
? ? ?方法:指定到實際關(guān)聯(lián)的屬性:即:@OneToMany (mappedBy = "courseId")
轉(zhuǎn)載于:https://www.cnblogs.com/snake-hand/archive/2013/06/12/3133048.html
總結(jié)
以上是生活随笔為你收集整理的(转)hibernate 注解的问题(异常)集合的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 片言碎语!!
- 下一篇: cocos2dx游戏开发必备工具之Phy