Uninitialized primary key (id = 0)

#1
Exception in thread "main" [ObjectDB 2.2.9_04] javax.persistence.RollbackException
Failed to commit transaction: Attempt to reuse an existing primary key value (image.Meta:0) (error 613)
at com.objectdb.jpa.EMImpl.commit(EMImpl.java:277)

I check the db by explorer.jar, and find the only one record is id=0.

What situation will be id=0?

TIA

#2

This happens if you define an id field with no @GeneratedValue and you do not initialize it manually.

ObjectDB Support
#3

Yes, at first, there is no @GeneratedValue, but it do not work after I add this command:

@GeneratedValue(strategy=GenerationType.IDENTITY)

Should I remove the whole db?

TIA

#4

Adding @GeneratedValue should solve the problem, unless you already have entity objects with IDs > 0 that you previously set manually.

You may also try a different strategy. For example, if you use a sequence or table - you can set an initial ID which is larger than any existing ID to avoid any conflict.

ObjectDB Support

Reply