This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes hibernate primary key mapping - sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate primary key mapping - sequence" Watch "hibernate primary key mapping - sequence" New topic
Author

hibernate primary key mapping - sequence

Eugene Babiev
Greenhorn

Joined: Jan 26, 2006
Posts: 19
in the following xml the sequence is defined (for Oracle DB):

<id name="id" column="PENDING_ORDER_ID"
unsaved-value="-1">
<generator class="native">
<param name="sequence">
UNIQUE_ID_SEQUENCE</param>
</generator>
</id>

but what if the alternative database is MySQL which doesn't have sequences. Then what the hibernate will do in this case? Should i write another MySQL mapping to exclude sequence param from mapping?

regards,
Eugene
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You can't use sequences with MySQL, so I presume Hibernate will throw some sort of exception if you try. The sequence generation strategy will only work with those DBs that support sequences (DB2, PostgreSQL, Oracle, SAP, McKoi and Firebird). Its a little gotcha in Hibernate's "one mapping layer for all databases" claim, albeit an understandable and documented one.

However that mapping you posted is a native generation strategy, not a sequence generation stategy. Native will use another generator depending on the database. If its Oracle for example Hibernate will look for a sequence called UNIQUE_ID_SEQUENCE. If its MySQL, it will try to use something else (probably identity - but you'll find that out when you run it against your MySQL schema).


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Why not try it and see what happens?


There is no emoticon for what I am feeling!
 
 
subject: hibernate primary key mapping - sequence
 
Similar Threads
Hibernate : Could not parse mapping document from resource
Hibernate - SQLGrammarException : could not get next sequence value
Hibernate is saving the id as -E.000E-78
How to specify relationship in mapping file
Hibernate: confusion how to include seperate attribute in many-to-many mapping file