我正在尝试基于唯一但非主键列连接两个表。为了简单起见,我以(Books,Author)为例,我想基于number1 = id1
将Book与Author结合在一起。
[id1
在作者表中是唯一的。
书-表映射:
<class name="example.Book" table="booksTable">
<composite-id>
<key-property name="number1" type="int">
<column name="n1" precision="8" scale="0" />
</key-property>
<key-property name="number2" type="int">
<column name="n2" precision="3" scale="0" />
</key-property>
<key-property name="number3" type="int">
<column name="n3" precision="8" scale="0" />
</key-property>
</composite-id>
</class>
作者表映射:
<class name="example.Author" dynamic-update="true">
<composite-id>
<key-property name="id1" type="int">
<column name="id1" precision="8" scale="0" />
</key-property>
<key-property name="id2" type="int">
<column name="id2" precision="3" scale="0" />
</key-property>
</composite-id>
<union-subclass name="example.Author1" table="authorTable1" />
<union-subclass name="example.Author2" table="authorTable2" />
</class>
所以我将以下内容添加到“图书”映射中:
<many-to-one name="author" property-ref="id1" not-found="ignore" class="example.Author" fetch="join" lazy="false">
<column name="n1" />
</many-to-one>
但是我得到:
Invocation of init method failed; nested exception is org.hibernate.MappingException: property-ref [id1] not found on entity [example.Author]
我见过这个question,但我不知道这里是否是相同的休眠错误。
我遇到同样的问题。我正在做一些从Hibernate 3到Hibernate 5的迁移。这曾经与Hibernate 3一起工作,但是与Hibernate 5一起工作却没有。真正的问题是Book Mapping的复合ID的关键属性之一是外键,当我们尝试与Author联接时,它显示为“在实体[xxxxxx]上找不到属性参考[xxxx]”