Seems to work fine:
Session s = getSessions().openSession();
Classb b1 = new Classb("b1");
Classb b2 = new Classb("b2");
Classa a = new Classa();
a.setP1( b1 );
a.setP2( b2);
Transaction t = s.beginTransaction();
s.save( a );
t.commit();
s.close();
The mapping:
Code:
<hibernate-mapping
package="org.hibernate.test.kgi">
<class name="Classa" table="`classes_a`" >
<id name="id" unsaved-value="null">
<generator class="native"/>
</id>
<many-to-one name="p1" class="Classb" cascade="all"/>
<many-to-one name="p2" class="Classb" cascade="all"/>
</class>
<class name="Classb" table="`classes_b`">
<id name="id" unsaved-value="null">
<generator class="native"/>
</id>
<property name="name"/>
</class>
</hibernate-mapping>