一对多关系和其他对象关系 [英] One to many relationship and Other object relation
问题描述
我有一个叫做 Customer 的对象,它会有与地址对象(一对一关系)和门票对象(一对多关系) STRONG>。 [每位顾客可以有许多票> 。并且每张门票都有一个付款对象(一对一关系)。我在hibernate注释中指定了关系。
执行测试时出现以下错误,
初始化SessionFactory创建failed.org.hibernate.AnnotationException:未知mappedBy in:com.test.model.Tickets.payment,引用属性unknown:com.test.model.Payment.tickets
线程mainjava中的异常。 lang.ExceptionInInitializerError
如果我在java中删除了 Payment对象及其引用以及 hibernate.cfg.xml 中的,对三个对象(客户,地址和票据)均可正常工作。如果为客户添加付款对象,它不起作用。我在哪里错了这个代码?
我的对象,
客户:
地址:
门票:
付款方式:
$ b 测试程序是:
Hibernate Configuration是:
Payment
中没有名为票据
的属性。取而代之的是名为 ticket
(单数)的属性。应该使用以下内容: mappedBy =ticket
I am learning hibernate. It may be a basic question, I am not able to figure out the issue,
I am having an object called Customer, It will have a relationship with address object (one-to-one relation) and Tickets object (one-to-many relation). [Each customer can have many tickets]. And Each ticket will have a payment object (One-to-one relation). I specified the relation in hibernate annotation.
I am getting the below error when executing the test,
Initial SessionFactory creation failed.org.hibernate.AnnotationException: Unknown mappedBy in: com.test.model.Tickets.payment, referenced property unknown: com.test.model.Payment.tickets
Exception in thread "main" java.lang.ExceptionInInitializerError
If I remove the Payment object and their reference in java as well as in hibernate.cfg.xml, It works fine with three objects (Customer, Address, and Tickets). If add a Payment object for the customer , It is not working. Where am i wrong in this code ?
My objects, Customer :
Address :
Tickets :
Payment :
Test program is :
Hibernate Configuration is :
As said in the error message, there is no property named tickets
in Payment
. Instead of it there is property named ticket
(singular). Following should be used:
mappedBy="ticket"
这篇关于一对多关系和其他对象关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!