-->
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: id generator
PostPosted: Tue Jun 05, 2007 1:06 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:
PostPosted: Wed Jun 06, 2007 5:34 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
"event_id" int(10) unsigned NOT NULL auto_increment,

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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.