-->
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.  [ 2 posts ] 
Author Message
 Post subject: A question about how Hibernate do setId
PostPosted: Fri Oct 08, 2004 10:16 pm 
Newbie

Joined: Fri Oct 08, 2004 10:11 pm
Posts: 6
hello there,

im a noobie.

For mapping a class to database table, we usually have this Identifier/id column.

I found out that the class implementation provided by me, not necessarily need to have function to setId; something like public void setId(int id)

Even the id attribute could be put as private to the class.
So i wonder, how could hibernate help me extract/set the id from database table accordingly?

Any reference/help/links/articles are very much appreciated

Regards,
Robin


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 09, 2004 9:14 am 
Newbie

Joined: Thu Sep 25, 2003 7:21 pm
Posts: 17
usually one would leave getID() public, make setID(..) private and let hibernate generate the identifier like this

Code:
<class name="whatever" table="whatever">
  <id name="id" column="id">
     <generator class="native" />
  </id>
</class>


there are a number of different generators (besides native) available, and you could even implement your own

alternatively you could not have a getID or setID property at in your domain object all like this

Code:
<class name="whatever" table="whatever">
  <id column="id">
     <generator class="native" />
  </id>
</class>


you can then retrieve the id with session.getIdentifier, but because the ID is not in the object you can't detach/reatach these objects from a session


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