Hi everyone, I'm writing this, to know if there is a way to map a one-to-many relationship, using a entity at one side and a foreing-key at the other as a Long/Integer. I'll put my example:
public class ClassA { __ private idClassA __ private List<ClassB> classesB; }
public class ClassB { __private idClassB; __private Long idClassA_FK; }
this are my hbm.xml files for both entities:
<class name="ClassA" table="CLASS_A"> __<id name="idClassA" type="long"> ____<column name="ID" sql-type="BIGINT" /> ____<generator class="native" /> __</id> __<bag name="classesB" lazy="false" cascade="save-update,delete-orphan"> ____<key column="ID_CLASS_A" /> ____<one-to-many class="ClassB" /> __</bag> </class>
<class name="ClassB" table="CLASS_B"> __<id name="idClassB" type="long"> ____<column name="ID" sql-type="BIGINT" /> ____<generator class="native" /> __</id> __<property name="idClassA_FK"> ____<column name="ID_CLASS_A" sql-type="BIGINT" /> __</property> </class>
I don't get any error from this, It works well. But I have the next problem: when I persist a ClassA the ClassB.idClassA_FK value is null, so, I need to iterate over the list, and set the new Id of ClassA into this FK, and then make an update again. I wanna know if exist a way, that hibernate sets the ClassB.idClassA_FK automatically when I send to persist ClassA.
Thanks
|