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 ?