-->
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.  [ 5 posts ] 
Author Message
 Post subject: Question regarding Session.load()
PostPosted: Mon Jun 27, 2005 2:23 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
Employee table has a composite primary key - empno, companyno.

How do I load an instance of Employee object using Session.load() method? load() method takes "id" as the 2nd parameter. In this case, i'd need to pass both empno, companyno. how do i do that?

I apologize for asking very basic qns... but i couldnt any suitable API to achieve this...

Thanks in advance for your help!

~ Nilesh


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 27, 2005 2:30 pm 
Newbie

Joined: Fri Jun 24, 2005 3:32 pm
Posts: 11
Each table has it's own unique ID. (the primary key). Since you are loading an individual employee, then there could only be one of those employees in the table. Would you really have two of the same employee in this table?

This is the "id" that the load() method is referring to. If you have to grab multiple employees, then you will need a query instead of an idividual load().


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 27, 2005 2:36 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
Neelixx wrote:
Each table has it's own unique ID. (the primary key). Since you are loading an individual employee, then there could only be one of those employees in the table. Would you really have two of the same employee in this table?

This is the "id" that the load() method is referring to. If you have to grab multiple employees, then you will need a query instead of an idividual load().


Employee table has employeeno, companyno as composite primary key. So if i have to load an Employee instance I need to pass both the parameters.

I believe load() takes 2nd argument as "id" which i refer to be a primary key...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 27, 2005 2:49 pm 
Newbie

Joined: Fri Jun 24, 2005 3:32 pm
Posts: 11
nrbhattad wrote:
I believe load() takes 2nd argument as "id" which i refer to be a primary key...


What column do you have defined in your hibernate mapping for your employee object? 'id' in the load() method refers to the key that you defined in your hibernate mapping. It is the same id that you get back in object.getId(), unless you modified the method in your class.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 8:29 am 
Regular
Regular

Joined: Thu Apr 29, 2004 5:08 pm
Posts: 56
Location: Montreal, Quebec, Canada
First, if you can use a surrogate key instead of composed-id, it is really recommended.

Second, create a class to represent the id itself.

See documentation, section "Components as composite identifiers" of hibernate doc.

_________________
- Frank


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.