Hi,
I'm using hibernate 3.1.2 and hibernate-tools 3.1.0b4.
I need to support both Oracle and MySQL. Ordinary "native" generation works ok. However recently a co-worker changed the id generation to this so the sequence name can be explicitly defined:
<id name="id" column="msl_id" type="java.lang.Long">
<generator class="native">
<param name="sequence">msl_seq</param>
</generator>
</id>
We run org.hibernate.tool.hbm2ddl.SchemaExportTask to generate a schema-file which is used to define the database tables (ie database schema is generated from hbm.xml files).
With the above "sequence" param within the native generator clause, the schema generated when using Oracle dialect works nicely; Oracle sequences are declared.
Unfortunately it doesn't work with MySQL; at runtime a JDBC error occurs as follows:
[junit] WARN org.hibernate.util.JDBCExceptionReporter SQL Error: 1109, SQLState: 42S02
[junit] ERROR org.hibernate.util.JDBCExceptionReporter Unknown table 'msl_seq' in field list
[junit] ERROR gfg.mobile.ts.core.TransactionBase Transaction Process: Unexpected exception
[junit] org.hibernate.exception.SQLGrammarException: could not get next sequence value
[junit] at org.hibernate.exception.SQLStateConverter.convert(SQLStateCon
verter.java:65)
[junit] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:43)
[junit] at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator
.java:96)
....
Any suggestions on how to define things in the hbm.xml file so it works on both Oracle and MySQL would be greatly appreciated.
Regards, Simon
|