-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Many to one mapping right?
PostPosted: Wed Mar 02, 2005 1:57 am 
Beginner
Beginner

Joined: Fri Dec 10, 2004 11:46 pm
Posts: 37
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: None

Name and version of the database you are using: MySQL

The 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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.