0

As we know if we use identity ID Generator in Hibernate and if we dont set the primary key value to the entity object then database will insert the primary key value.

But If we are using identity ID Generator and still we set the primary key value to the entity class object like entityClassObject.setPrimaryKeyNo(10) then which primary key will be stored in the database?

  1. Database Provided Primary key
  2. Ours provided primary key

Can someone prove it ?

Community
  • 1
  • 1
ALTAF
  • 41
  • 11

1 Answers1

0

Database provided primary key. More accurately, primary key provided by the persistence provider.

From javadoc of GenerationType.IDENTITY:

IDENTITY

public static final GenerationType IDENTITY

Indicates that the persistence provider must assign primary keys for the entity using a database identity column.

From Hibernate-5.3.1.Final User Guide:

2.6.9. Using IDENTITY columns

For implementing identifier value generation based on IDENTITY columns, Hibernate makes use of its org.hibernate.id.IdentityGenerator id generator which expects the identifier to generated by INSERT into the table.

Minar Mahmud
  • 2,577
  • 6
  • 20
  • 32