Hibernate version: 2.1.x
Code between sessionFactory.openSession() and session.close():
Code:
I have 2 POJOs
1- Principal
2- Role
1-Init Principal POJO
1b- session.save(Principal);
2- Set principal to Role POJO
2b- session.save(Role)
I'm wondering how the many-to-one mapping works?
When I run my code, the PrincipalId column gets inserted into the Role table instead of the Principal. If I use ref-property, then I get the expected result. Just trying to understand what the dif is?
Thanks
Full stack trace of any exception that occurs: NoneName and version of the database you are using: MySQLThe generated SQL (show_sql=true):Code:
Hibernate: insert into Principals (Principal, Password, UUID, Active) values (?, ?, ?, ?)
Hibernate: insert into Roles (Role, RoleGroup, Principal) values (?, ?, ?)
Mapping documents:Code:
<class name="com.mamoth.Principal" table="Principals">
<id name="principalID" column="PrincipalID" type="int">
<generator class="identity" />
</id>
<property name="principal" type="java.lang.String">
<column name="Principal" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="password" type="java.lang.String">
<column name="Password" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="uuid" type="java.lang.String">
<column name="UUID" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="active" type="boolean">
<column name="Active" sql-type="bit"/>
</property>
</class>
<class name="com.mamoth.Role" table="Roles">
<id name="roleID" column="RoleID" type="int">
<generator class="identity" />
</id>
<property name="role" type="java.lang.String">
<column name="Role" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="roleGroup" type="java.lang.String">
<column name="RoleGroup" sql-type="varchar" length="50" not-null="false"/>
</property>
<many-to-one name="principal" column="Principal" class="com.mamoth.Principal"/>
</class>