EJB3中使用Oracle序列的问题

今天在EJB3.0中使用Oracle序列,老报错,错误如下:
Caused by: Exception [TOPLINK-7027] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The sequence named [USERS_ID_SEQ] is setup incorrectly. Its increment does not match its pre-allocation size.
原来的代码如下:
@Id
@SequenceGenerator(name = "USER_ID_GEN", sequenceName = "USERS_ID_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "USER_ID_GEN")
@Column(name="USER_ID", nullable = false)
private Long userId;
后来查了资料才知道原来@SequenceGenerator的默认值是50而我的USERS_ID_SEQ设置的是递增1。所以出了错。要设置下allocationSize的值。allocationSize的说明如下:
allocationSize (Optional) The amount to increment by when allocating sequence numbers from the sequence.
详细情况见SUN官方文档
改后的代码就是:
@Id
@SequenceGenerator(name = "USER_ID_GEN", sequenceNam= "USERS_ID_SEQ", allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "USER_ID_GEN")
@Column(name="USER_ID", nullable = false)
private Long userId;

你可能感兴趣的:(ejb)