-->
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.  [ 3 posts ] 
Author Message
 Post subject: Multiple primary key
PostPosted: Wed Apr 11, 2007 6:02 am 
Newbie

Joined: Tue Apr 10, 2007 7:59 pm
Posts: 4
Location: Philippines
hi,
i'm looking for sample application that shows how to map multiple primary key.i am mapping a table that has two primary key these are the following fields :
computer_id, user_id
thanks in advance.

_________________
I love being a member of this forum.I have learned many things from the expert.


Top
 Profile  
 
 Post subject: Re: Multiple primary key
PostPosted: Wed Apr 11, 2007 9:48 pm 
Newbie

Joined: Tue Apr 10, 2007 7:59 pm
Posts: 4
Location: Philippines
njel_valdez wrote:
hi,
i'm looking for sample application that shows how to map multiple primary key.i am mapping a table that has two primary key these are the following fields :
computer_id, user_id
thanks in advance.



i was reading the nhibernate reference material and i found the solution to my problem.here is the sample hbm.xml file. i use the <composite-id> to tag multiple primary keys.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="WindowsApplication1.User, WindowsApplication1" table="users">
<composite-id>
<key-property name="Id" column="Computer_id" type="String" length="20"/>
<key-property name="UserID" column="user_id" type="String" length="40"/>
</composite-id>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>

_________________
I love being a member of this forum.I have learned many things from the expert.


Top
 Profile  
 
 Post subject: Question about this
PostPosted: Tue Apr 17, 2007 8:30 am 
Newbie

Joined: Mon Apr 16, 2007 3:20 pm
Posts: 7
Hi, Is it this simple. I'm pretty sure I've tried this, but am having such problems getting a composite-id to work. My composite id is made up of 4 fields. Does that mean i need to do anything different?

Also, are there special wrappers or tags i need to place is the class file? Thanks for your help. I've really been struggling with this for a day or two now, and dont' know what to do. Thanks a lot. Here's my mapping just in case ( I have 3 different versions of it, bcz I've seen so many different examples, but here is the latest):

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="EmployeeTimeTracker.EmpTime, EmployeeTimeTracker" table="dbo.EMPLOYEE_TIME_USED">
      <composite-id>      
          <key-many-to-one name="EmpID" column="EMPLOYEEID" type="String" length="50" />                   
         <key-many-to-one name="TimeType" column="TIME_ID" type="String" length="1" />                  
         <key-many-to-one name="AttendReason" column="REASON_ID" type="Integer" />                  
         <key-property name="DateUsed" column="DATE_USED" type="DateTime" />                             
      </composite-id>
                  
      <property name="HoursUsed" column="HOURS_USED" type="Double" />   
      
      <many-to-one name="EmpID" class="EmployeeTimeTracker.Employee, EmployeeTimeTracker">
         <column name="EMPLOYEEID" />
      </many-to-one>
      <many-to-one name="TimeType" class="EmployeeTimeTracker.TimeType, EmployeeTimeTracker">
         <column name="TIME_ID" />
      </many-to-one>
      <many-to-one name="AttendReason" class="EmployeeTimeTracker.AttendReason, EmployeeTimeTracker">
         <column name="REASON_ID" />
      </many-to-one>
   </class>
</hibernate-mapping>


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

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.