[英]Unable to make 'one-to-one' relationship between the two classes
What shall I do in the following xml
to make a one-to-one
relationship between Country
class and PM
class ? 我应该在以下xml
中做什么one-to-one
在Country
类和PM
类之间建立one-to-one
关系?
<class name="pojo.Country" table="country">
<id name="c_id">
<generator class="increment" />
</id>
<property name="name_c" />
<one-to-one class="pojo.PM" name="name_pm" />
</class>
<class name="pojo.PM" table="pm">
<id name="c_id">
<generator class="increment" />
</id>
<property name="name_pm" />
</class>
I am making a one-to-one relation between name_pm
which is a property defined inside the PM
class and name_c
which is a property defined inside Country
class. 我正在name_pm
这是PM
类内部定义的属性)和name_c
(是Country
类中定义的属性)之间name_pm
一对一的关系。 The problem occurs when I write : 我写的时候会出现问题:
<one-to-one class="pojo.PM" name="name_pm" />
It starts to search the property name_pm
inside the class PM
when it should search inside the Country
class. 当它应该在Country
类中进行搜索时,它将开始在PM
类中搜索属性name_pm
。
How do I define a One-toOne
relation between name_pm and name_c ? 如何定义name_pm和name_c之间One-toOne
关系?
Seems like wrong syntax. 似乎语法错误。
Try 尝试
<one-to-one name="pmNameInCountryPojo" class="pojo.PM"
cascade="save-update"></one-to-one>
The exception itself points to the solution. 异常本身指向解决方案。
You need to create getter and setter for name_pm
in your pojo.Country
class. 您需要在pojo.Country
类中为name_pm
创建getter和setter。
and add 并添加
<one-to-one class="pojo.Country" name="${variable-name}" />
in your pojo.PM
configuration and create setter and getter for respective variable in PM
class. 在您的pojo.PM
配置中,并为PM
类中的各个变量创建setter和getter。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.