How to add a "where" to Hibernate many-to-one?
I currently have a many-to-one relationship set up from class Exp to class开发者_JS百科 Fin like this:
From Exp.hbm.xml:
<many-to-one not-found="ignore" cascade="none" update="false" insert="false"
unique="false" class="model.Fin" name="Fin"
column="SAK_EXP" property-ref="SakTrans" />
What I need to do is add a restriction to this.
In class Fin, there's a property IndCrDb
, and I only want to create the many-to-one relationship with Fin where this property has value 'C'.
<property name="IndCrDb" column="IND_CR_DB" type="string"
not-null="false" length="1" unique="false" update="true"
insert="true" optimistic-lock="true" lazy="false"/>
Is there a way to do this? I know I could change the setter in Exp.java to not set if the IndCrDb is wrong but that doesn't seem like a good option.
Sounds like maybe what you need is an association class.
精彩评论