-->
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 generation, native and sequence
PostPosted: Tue Mar 28, 2006 1:23 am 
Newbie

Joined: Wed Jul 27, 2005 7:53 am
Posts: 4
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


Top
 Profile  
 
 Post subject: Solved
PostPosted: Tue Mar 28, 2006 5:32 pm 
Newbie

Joined: Wed Jul 27, 2005 7:53 am
Posts: 4
Problem solved.

The <generator> syntax shown *is* actually portable across Oracle and MySQL. That is interesting in itself; it isn't documented anywhere I can find. The hibernate sourcecode is clear though: the SequenceGenerator class looks for a param with name "sequence", while the IdentityGenerator completely ignores it (see also IdentifierGeneratorFactory). So far so good.

The problem was that my co-worker *also* changed the dialect declaration to be OracleDialect (buried in a spring config file elsewhere in the project). Obvious in hindsight...


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.