-->
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: ids for this class must be manually assigned before calling
PostPosted: Mon Sep 21, 2009 11:11 pm 
Newbie

Joined: Thu Jul 30, 2009 1:09 am
Posts: 2
Hi,

i am developing one small app using hibernate .when am running app am getting ids for this class must be manually assigned before calling save() eror.

the table am going insert data in to that PK having autoincreamentnumber.
so no need to set value for that .

any one please tell me why am getting this errror


Anand Pasunoori
anand853@gmail.com


Top
 Profile  
 
 Post subject: Re: ids for this class must be manually assigned before calling
PostPosted: Wed Sep 23, 2009 6:39 am 
Beginner
Beginner

Joined: Wed Jul 09, 2008 5:34 am
Posts: 41
Location: Brno, Czech Republic
How does the mapping for your ID looks like? It sounds that you want to use the "native" generator.

http://docs.jboss.org/hibernate/stable/ ... aration-id


Top
 Profile  
 
 Post subject: Re: ids for this class must be manually assigned before calling
PostPosted: Wed Sep 23, 2009 12:38 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Here's some info on key generation strategies:

http://jpa.ezhibernate.com/Javacode/lea ... jpamapping

Quote:
@GeneratedValue JPA Annotation

Quite often in these tutorials, we have used the @GeneratedValue annotation to have thedatabase generate a unique primary key for us. We have used the default Generation Type in each of our examples, but there are actually four different strategies for having the primary key generated by the database. Those four options are:

AUTO
IDENTITY
TABLE
SEQUENCE
javax.persistence.GenerationType.AUTO

The AUTO generation strategy is the default, and this setting simply chooses the primary key generation strategy that is the default for the database in question, which quite typically is IDENTITY, although it might be TABLE or SEQUENCE depending upon how the database is configured. The AUTO strategy is typically recommended, as it makes your code and your applications most portable.

javax.persistence.GenerationType.IDENTITY

The IDENTITY option simply allows the database to generate a unique primary key for your application. No sequence or table is used to maintain the primary key information, but instead, the database will just pick an appropriate, unique number for Hibernate to assign to the primary key of the entity. With MySQL, the first lowest numbered primary key available in the table in question is chosen, although this behavior may differ from database to database.

javax.persistence.GenerationType.Sequence

Some database vendors support the use of a database sequence object for maintaining primary keys. To use a sequence, you set the GenerationType strategy to SEQUENCE, specify the name of the generator annotation, and then provide the @SequenceGenerator annotation that has attributes for defining both the name of the sequence annotation, and the name of the actual sequence object in the database.

Here's what the getId() method of the Snafu class would look like if we used a SEQUENCE GenerationType:


http://jpa.ezhibernate.com/Javacode/lea ... jpamapping

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.