This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

hibernate primary key mapping - sequence  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not try it and see what happens?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!