0

I am trying to generate a primary key using Sequence generator in JPA and all the parameters are properly set as shown

    @Id
@Column(name = "TEST_ID", unique = true, nullable = false, precision = 12)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IB_ENRACTDSCRD_TESTID_GENERATOR")
@SequenceGenerator(name = "IB_ENRACT_TESTID_GENERATOR", sequenceName = "TEST_ID" )  
private Long testId;

I set values into the entity object (except for id) and creating a row in by calling the function as shown

    public < T > T create( T t )
{
    this.getEntityManager( ).persist( t );
    this.getEntityManager( ).flush( );
    return t;
}

But value at t shows a null value for primary key and I am getting the following error at flush()

javax.ejb.EJBException: See nested exception; nested exception is: <openjpa-2.0.2-SNAPSHOT-r422266:1084264 fatal store error> org.apache.openjpa.persistence.OptimisticLockException: Unable to obtain an object lock on "null". 
<openjpa-2.0.2-SNAPSHOT-r422266:1084264 fatal store error> org.apache.openjpa.persistence.OptimisticLockException: Unable to obtain an object lock on "null". 

Can someone help regarding why the Id key is not setting to null ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Kesavacharan
  • 318
  • 3
  • 14
  • There is a problem with the T you are passing to persist that has to do with optimistic locking. You can't get the id from persist until this is resolved. Show the full entity and error – Chris Nov 20 '13 at 21:22
  • The issue is found the sequence name TEST_ID is not present in database - I checked it in all_sequences table. Thank you – Kesavacharan Nov 21 '13 at 03:53

0 Answers0