在oracle数据库中排序

时间:2013-01-15 15:23:29

标签: java oracle jpa eclipselink

我需要对表使用GenerationType.sequence策略 我在课堂上写了以下注释:

@Id
@SequenceGenerator(name="SEQ_PERFIL", sequenceName="SEQ_PERFIL",allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_PERFIL")
@Column(name="PER_CODPERFIL", nullable = false)
private long perCodperfil;

要插入我使用此代码:

entityManager.getTransaction().begin();
entityManager.persist(entity);
entityManager.flush();
entityManager.refresh(entity);
entityManager.getTransaction().commit();

当我插入序列时会增加(我在数据库中显示),但插入失败,因为主键为空

It said :
Error Code: 1400
Call: INSERT INTO PERFIL (PER_CODPERFIL) VALUES (?) bind => [1 parameters bound]
Query: InsertObjectQuery(24)

它说PER_CODPERFIL为空 我使用Eclipse-link和Oracle DB

eclipse链接记录的句子是:

15:05:36,651 INFO    [EclipseLog] SELECT SEQ_SIAC_PERFIL.NEXTVAL FROM DUAL   
15:05:36,761 INFO    [EclipseLog] INSERT INTO PERFIL (PER_CODPERFIL) VALUES (?) bind => [null]
15:05:36,773 INFO    [EclipseLog] SELECT 1 FROM DUAL

0 个答案:

没有答案