我有一个Node
与NodeData
s 相关的。这些NodeData
s 有修订,并且 Node 有一列latestRevision
告诉它哪个是最后一个修订。
我正在尝试找出我需要的映射,以便通过latestRevision
in过滤下面的集合Node
。
<class name="Node" table="RatNodes">
<id name="id">
<generator class="native"/>
</id>
<set fetch="join" name="nodeDatas" table="RatNodeData" inverse="true" access="field" cascade="all-delete-orphan" order-by="dataOrder asc">
<key column="nodeID" on-delete="cascade"/>
<one-to-many class="NodeData"/>
<filter name="revisionFilter" condition="revision = latestRevision"/>
</set>
<property name="questionNumber" access="field"/>
<property name="type" access="field"/>
</class>
<class name="NodeData" table="RatNodeData">
<composite-id>
<key-property name="nodeID" access="field"/>
<key-property name="key" access="field" column="dataKey"/>
<key-property name="order" access="field" column="dataOrder"/>
<key-property name="revision" access="field"/>
</composite-id>
<property name="value" access="field" type="EncodedStringUserType" column="dataValue"/>
</class>
当我启用过滤器时,这个映射的结果是一个错误:
Caused by: com.jnetdirect.jsql.JSQLException: Invalid column name 'latestRevision'.
它吐出的查询是:
select nodedatas0_.nodeID as nodeID1_, nodedatas0_.dataKey as dataKey1_, nodedatas0_.dataOrder as dataOrder1_, nodedatas0_.revision as revision1_, nodedatas0_.nodeID as nodeID46_0_, nodedatas0_.dataKey as dataKey46_0_, nodedatas0_.dataOrder as dataOrder46_0_, nodedatas0_.revision as revision46_0_, nodedatas0_.dataValue as dataValue46_0_ from RatNodeData nodedatas0_ where nodedatas0_.revision = nodedatas0_.latestRevision and nodedatas0_.nodeID=? order by nodedatas0_.dataOrder asc
我可以说这是错误的,因为它正在寻找,latestRevision
但NodeData
我不知道如何告诉它寻找Node
。这在休眠中可能吗?如果我只是使用 SQL,这似乎是一个非常简单的查询。