Identity columns and sequences in Hibernate
By: Dorris Printer Friendly Format
For databases that support identity columns (DB2, MySQL, Sybase, MS SQL), you can use identity key generation. For databases that support sequences (DB2, Oracle, PostgreSQL, Interbase, McKoi, SAP DB) you can use sequence style key generation. Both of these strategies require two SQL queries to insert a new object. For example:
<id name="id" type="long" column="person_id">
<generator class="sequence">
<param name="sequence">person_id_sequence</param>
</generator>
</id>
<id name="id" type="long" column="person_id" unsaved-value="0">
<generator class="identity"/>
</id>
For cross-platform development, the native strategy will, depending on the capabilities of the underlying database, choose from the identity, sequence and hilo strategies.
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
Fetching strategies in Hibernate
equals() and hashCode() in Hibernate
Tuplizers (org.hibernate.tuple.Tuplizer) in Hibernate
EntityNameResolvers in Hibernate
Identity columns and sequences in Hibernate
Assigned identifiers in Hibernate
Primary keys assigned by triggers in Hibernate
Step by Step Hibernate - Your First Hibernate Application
A sample Hibernate Web Application using Servlets
Contextual sessions in Hibernate
Archived Comments
1. This was the first clear and straight-forward exam
View Tutorial By: Steve at 2013-01-02 22:58:32
2. Brettkip
View Tutorial By: Brettkip at 2017-06-11 19:36:37
3. Brettkip
View Tutorial By: Brettkip at 2017-07-29 03:53:33