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: when to use generator class="assigned" vs 'native'
PostPosted: Thu Feb 04, 2010 9:17 am 
Newbie

Joined: Wed Jan 06, 2010 9:09 pm
Posts: 14
Hi All,

I auto-generated by Hibernate mapping files from an existing MySQL schema. Each of the mapping files specifies the id as:
<generator class="assigned"/>.
My code works best when I use the 'native' generator however to match the fact that MySQL auto generates a new id when a new row is inserted.

So my question is when would you use assigned over native?

Thanks,
Fred


Top
 Profile  
 
 Post subject: Re: when to use generator class="assigned" vs 'native'
PostPosted: Wed Feb 10, 2010 9:43 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi,

along with "assigned" and "native" there are many other generator types, see
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html
chapter 5.1.4.1. Generator

Quote:
My code works best when I use the 'native' generator however to match the fact that MySQL auto generates a new id when a new row is inserted.


Yes, 'native' generator is very comfortable for this purpose.
Anyway this approach has some serious disadvantages:
1. Performance:
With 'native' generator the row is inserted immediately when persisting a new object.
With the other approaches the inserts are deferred to the flush/commit action and can benefit from the batching feature.
2. Traceability: when enabling sql-logging with 'native' generator you cannot see with which ID the new persisted object was inserted into database.


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.