(转)hibernate 注解的问题(异常)集合

1,问题:An AnnotationConfiguration instance is required to use <mapping class="vo.Student"/>

解答:错误:SessionFactory factory = new Configuration().configure().buildSessionFactory(); //这句是用映射文件为xml的
<wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">正确:SessionFactory factory = new AnnotationConfiguration().configure().buildSessionFactory();//这句是用于注解的</span><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">2,问题:@OneToOne or @ManyToOne on vo.StuCour.student references an unknown entity: vo.Student</span><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">解答:错误原因(1):配置文件没有添加映射</span><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">方法:加上配置:在hibernta.hfg.xml&lt;mapping class="vo.Student"/&gt;</span><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">错误原因(2):在实体类public class ClassName上面没有加实体注解,</span><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">方法:加上注解:@Entity</span><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">@Table(name = "Student", catalog = "sms")</span><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">3,问题:mappedBy reference an unknown target entity property: vo.StuCour.stuCours</span><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">错误原因:在one-to-many注解配置: @OneToMany (mappedBy = "StuCour"),mappedBy指向的是要关联的属性,而不是要关联的类,</span><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">如果这样配置,hibernate则会找vo.StuCour类下面的stuCours属性。但实际上没有这个属性,就会报上面的异常</span><br style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"></span><wbr style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px"><span style="color:rgb(70,70,70); font-family:Verdana,Arial,Helvetica,sans-serif; font-size:14px; line-height:21px">方法:指定到实际关联的属性:即:@OneToMany (mappedBy = "courseId")</span> </wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值