持久化实体时出现 EclipseLink 错误(id null)
EclipseLink error when persisting an entity ( id null )
Stacktrace 1:错误来自方法 "submitTicket" 第 74 行,即:em.persist(bean);
at com.sun.proxy.$Proxy237.creer(Unknown Source)
at projet.helpdesk.dao.__EJB31_Generated__TicketDao__Intf____Bean__.creer(Unknown Source)
at projet.helpdesk.form.CreationTicketForm.soumettreTicket(CreationTicketForm.java:74)
堆栈跟踪 2:
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-01502: index 'BDD2.TICKETS_PK' or partition of such index is in unusable state
Error Code: 1502
Call: INSERT INTO Tickets (ID_TICKET, DATE_ENVOI, DATE_FERMETURE, DESCRIPTION, ETAT, ID_EMPLOYE, ID_TECHNICIEN, PRIORITE, SUJET) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [9 parameters bound]
Query: InsertObjectQuery(projet.helpdesk.beans.Ticket@1d796c68)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
提到 ORA-1502 错误在我重新启动我的 PC 之后开始显示,在此之前它是描述重复值问题的 ORA-0001 错误。
当我通过 em.persist(bean);
插入 bean 时,主键又名 id_ticket 设置为空,它是 Oracle 中使用的触发器,用于增加值。
Java 持久性查询语言似乎为插入时没有值的主键生成 0,而不是将它们作为空对象发送,所以我只是更改了生成主键的 ORACLE 中的触发器,如下:
create or replace trigger "BI_TICKETS"
before insert on "TICKETS"
for each row
begin
if :NEW."ID_TICKET" is null or :NEW."ID_TICKET"=0 then
select "TICKETS_SEQ".nextval into :NEW."ID_TICKET" from dual;
end if;
end;
在条件中添加:NEW."ID_TICKET"= 0
,完成。
Stacktrace 1:错误来自方法 "submitTicket" 第 74 行,即:em.persist(bean);
at com.sun.proxy.$Proxy237.creer(Unknown Source)
at projet.helpdesk.dao.__EJB31_Generated__TicketDao__Intf____Bean__.creer(Unknown Source)
at projet.helpdesk.form.CreationTicketForm.soumettreTicket(CreationTicketForm.java:74)
堆栈跟踪 2:
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-01502: index 'BDD2.TICKETS_PK' or partition of such index is in unusable state
Error Code: 1502
Call: INSERT INTO Tickets (ID_TICKET, DATE_ENVOI, DATE_FERMETURE, DESCRIPTION, ETAT, ID_EMPLOYE, ID_TECHNICIEN, PRIORITE, SUJET) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [9 parameters bound]
Query: InsertObjectQuery(projet.helpdesk.beans.Ticket@1d796c68)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
提到 ORA-1502 错误在我重新启动我的 PC 之后开始显示,在此之前它是描述重复值问题的 ORA-0001 错误。
当我通过 em.persist(bean);
插入 bean 时,主键又名 id_ticket 设置为空,它是 Oracle 中使用的触发器,用于增加值。
Java 持久性查询语言似乎为插入时没有值的主键生成 0,而不是将它们作为空对象发送,所以我只是更改了生成主键的 ORACLE 中的触发器,如下:
create or replace trigger "BI_TICKETS"
before insert on "TICKETS"
for each row
begin
if :NEW."ID_TICKET" is null or :NEW."ID_TICKET"=0 then
select "TICKETS_SEQ".nextval into :NEW."ID_TICKET" from dual;
end if;
end;
在条件中添加:NEW."ID_TICKET"= 0
,完成。