该数据库是一个树型结构的
a
b extends a
c extends b
d extends a
配置时使用了joined-subclass进行配置
a有一个parentId的property
另外实例中c是d的parent,也就是说d.parentId=c.id
当给c配置一个one-to-one关系到d时(因为某些子节点常用,想直接挪出来),使用property-ref来引用d的parentId属性,居然发现找不到,数据库字段parent_id也找不到,请问这时应该怎么处理?
a
b extends a
c extends b
d extends a
配置时使用了joined-subclass进行配置
a有一个parentId的property
另外实例中c是d的parent,也就是说d.parentId=c.id
当给c配置一个one-to-one关系到d时(因为某些子节点常用,想直接挪出来),使用property-ref来引用d的parentId属性,居然发现找不到,数据库字段parent_id也找不到,请问这时应该怎么处理?
<hibernate-mapping> <class name="test.bean.Item" table="SC_Item">
<id name="id" column="id" />
<property name="name" column="name"/>
<property name="parentId" column="parent_id"/>
...
<many-to-one name="type" column="type_id" class="test.bean.Type" update="false"/>
<joined-subclass name="test.bean.Evaluation" table="SC_Evaluation_Item">
<key column="id"/>
<property name="evaluation" column="evaluation"/>
...
</joined-subclass>
...
<joined-subclass name="test.bean.Section" table="SC_Section_Item">
<key column="id" />
<joined-subclass name="test.bean.Comment" table="SC_Comment_Section">
<key column="id"/>
<property name="createTime" column="create_time"/>
<property name="content" column="content"/>
<one-to-one name="evaluation" class="test.bean.Item" cascade="all" property-ref="parentId" />
</joined-subclass>
...
</joined-subclass>
</class></hibernate-mapping>类似于这样写,hibernate很聪明,你告诉它是Item,property接受的参数是Evaluation,于是它自己就通过Item反过来找到Evaluation了,以前一直的惯性思维是,先创建一个Evaluation,再放入property,于是这样写
...
<one-to-one name="evaluation" class="test.bean.Evaluation" cascade="all" property-ref="parentId" />
...
便是错误的