Defining a Database Independent JPA uid Object

It turns out the following example works when using mysql 5.x, however it is not used when using the oracle 10g database.

Is there a way to define a unique identifier field that is independent of database technology?

@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="id") private long id; 

I tested this in sleep mode, and the following exception occurs only when using Oracle:

 org.hibernate.MappingException: Dialect does not support identity key generation 
+2
java hibernate jpa datanucleus
source share
2 answers

I researched using GenerationType.AUTO , and this is apparently the best option. This allows the JPA implementation to choose which is best for the storage system used.

0
source share

Using a database table is a portable way of generating identifiers.

The easiest way to use a table to generate identifiers is to specify TABLE as the generation strategy:

 @Id @GeneratedValue(strategy=GenerationType.TABLE) @Column(name="id") private long id; 

The provider will create a default table if you use schema generation; if not, you must specify an existing table:

 @TableGenerator(name="InvTab", table="ID_GEN", pkColumnName="ID_NAME", valueColumnName="ID_VAL", pkColumnValue="INV_GEN") @Id @GeneratedValue(generator="InvTab") @Column(name="id") private long id; 

http://www.oracle.com/technology/products/ias/toplink/jpa/howto/id-generation.html#table

+4
source share

All Articles