Im new at this, and not sure if to use the one-to-one mapping. I have an object of type "dokument" which has a "destinationer". when i create a "dokument" object, it has a "destinationer" as a property. The generated classes looks fine, just like i want them to be.
But when i do
session.save()
Only the "dokument" is saved, I belived the "destinationer" would be saved as well?
Hibernate version: 2.1.6
Mapping documents:
<hibernate-mapping>
<class name="com.hypergenic.kvis.remote.generated.model.Dokument" table="dokument">
<id name="id" type="int" column="id">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<property name="navn" type="string" not-null="true">
<meta attribute="use-in-tostring">true</meta>
<column name="navn" not-null="true" unique="true" index="dokument_navn" />
</property>
<property name="lastModified" type="long" not-null="true">
<meta attribute="use-in-tostring">true</meta>
</property>
<one-to-one name="destinationer" class="com.hypergenic.kvis.remote.generated.model.Destinationer">
<meta attribute="use-in-tostring">true</meta>
</one-to-one>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.hypergenic.kvis.remote.generated.model.Destinationer" table="destinationer">
<id name="id" type="int" column="id">
<meta attribute="scope-set">protected</meta>
<generator class="foreign">
<param name="property">dokument</param>
</generator>
</id>
<property name="visMenu" type="boolean" not-null="true">
<meta attribute="use-in-tostring">true</meta>
</property>
... a lot of other properties
<one-to-one name="dokument" class="com.hypergenic.kvis.remote.generated.model.Dokument" constrained="true" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Transaction tx= session.beginTransaction();
session.save(dokument);
tx.commit();
Name and version of the database you are using:
MySQL
|