-->
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.  [ 4 posts ] 
Author Message
 Post subject: do not want to use autogenerated id
PostPosted: Wed Oct 19, 2005 12:18 pm 
Beginner
Beginner

Joined: Wed Oct 19, 2005 12:03 pm
Posts: 21
Hi,

I am using a table named vehicle in my application with a unique value licenseNo(entered by the user). I tried to use that as the primary key instead of adding another variable vehicle_id which is auto-generated. But this did not work i was having problem saving the class. I did not want to use the autogenerated id because in all my classes I will have to add an extra varibale in the class solely for that purpose.

Also when I have to search a vehicle based on a license number I have to write an HQL query instead of using load for which I wud have to know the autoassigned vehicle_id, then i have to use the setters to set the values of all other fields and there are very many fields. I was hoping I cud do it with a single load instruction.

If someone know has had a similiar problem please let me know.

Thanx in advance
Shefali


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 1:30 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
Use in your mapping:

Code:

<id name="objectId" column="OBJECT_ID" type="java.lang.Integer">
            <generator class="assigned"/>
</id>



instead

Basil

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 1:30 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
Use in your mapping:

Code:

<id name="objectId" column="OBJECT_ID" type="java.lang.Integer">
            <generator class="assigned"/>
</id>



instead

Basil

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 1:47 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Basilio wrote:
Use in your mapping:

Code:

<id name="objectId" column="OBJECT_ID" type="java.lang.Integer">
            <generator class="assigned"/>
</id>



instead

Basil


Be sure to read the documentation on using the "assigned" generator. There are several issues regarding use of this type of ID. For example, Hibernate won't be able to tell by the ID alone whether to save or update the object.

And I don't think having to use an HQL Query over load() for the License # Search is, by itself, enough of a reason not to user surrogate keys in your database. There are many papers on this subject and I would suggest reading some of them.

For example: http://www.agiledata.org/essays/dataModeling101.html

And this statement "then i have to use the setters to set the values of all other fields and there are very many fields" is incorrect. Hibernate will populate your object(s) the same whether you're using a load() or HQL query.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


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