-->
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: id generator
PostPosted: Tue Jun 05, 2007 1:11 pm 
Newbie

Joined: Tue Jun 05, 2007 12:34 pm
Posts: 2
I am confused as to the different class values for the generator element necessary for id's in the mapping file.

I was trying to navigate through the first hibernate tutorial(http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html). The table Events has its id with a native generator:

Code:
<hibernate-mapping>

    <class name="events.Event" table="EVENTS">
        <id name="id" column="EVENT_ID">
            <generator class="native"/>
        </id>
        <property name="date" type="timestamp" column="EVENT_DATE"/>
        <property name="title"/>
    </class>

</hibernate-mapping>


I realize that this means hibernate will pick an appropriate class depending on the database. However, how should I create the table? I am testing on a mySQL database, but would like the ability to run on an Oracle database as well.
I tried creating the table with id as the primary key:

Code:
DROP TABLE IF EXISTS "test"."events";
CREATE TABLE  "test"."events" (
  "event_id" int(10) unsigned NOT NULL,
  "title" varchar(35) NOT NULL,
  "event_date" date NOT NULL,
  PRIMARY KEY  ("id")
);


I get the error (when trying to insert a row through hibernate):

12:49:03,577 ERROR JDBCExceptionReporter:78 - Field 'event_id' doesn't have a default value

Please let me know how the table should be created. Thanks!


Top
 Profile  
 
 Post subject: Re: Id generator
PostPosted: Wed Jun 06, 2007 12:16 am 
Newbie

Joined: Mon Dec 11, 2006 12:54 am
Posts: 14
Hi,

Which version of hibernate you are using? Just check out the link below, i think the problem is with the hibernate version which has a bug...

http://forum.hibernate.org/viewtopic.ph ... 2+identity


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 06, 2007 1:05 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
HI


There are several builtin id generator classes in hibernate. they used in varioues scenarios. and also anyone can use their own idgenerator class by implementing org.hibernate.id.IdentifierGenerator.

You can use native generator for following situations.

Your id column is one of identity, sequence or hilo types. So hibernate will picks suitable idgenarator upon the capabilities of the underlying database.


First select your own id field type. then deside what will be the hibernate id generator.



Amila

(Don't forget to rate if helps)


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.