views:

281

answers:

3

I'm looking for a tutorial explaining how to work with these 3 technologies, found this one, but it's working with HyperSql DB (yeah, I edited hibernate.cfg.xml to connect with MySql... but I just received a bunch of errors).

+1  A: 

Your table creation script is wrong for the hibernate generator strategy you're currently using. As I said, your primary key should be defined as autoincrement:

CREATE TABLE COURSES (
  COURSE_ID int(11) NOT NULL AUTO_INCREMENT,
  COURSE_NAME varchar(20) DEFAULT NULL,
  PRIMARY KEY (COURSE_ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

You should let SchemaExport generate your DDL for you, it will typically prevent such mistakes ;)

Pascal Thivent
+1  A: 

You might try setting <generator class="identity">. But native should also be working if you have set the database column to be auto_increment.

Bozho
+1  A: 

Problem solved using "Toad for MySQL" for creating the table, when setting the column to be the primary key, I just cleaned the "Default value" and did set the AutoIncrement property to true.

Wilhelm