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!