JPA序列生成器主键设置为null

时间:2013-11-20 19:03:04

标签: jpa sequence optimistic-locking

我正在尝试使用JPA中的Sequence生成器生成主键,并且所有参数都已正确设置,如图所示

    @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;

我将值设置为实体对象(id除外)并通过调用函数创建一行,如图所示

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

但是t处的值显示主键的空值,我在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". 

有人可以帮助解决为什么Id键没有设置为null?

0 个答案:

没有答案