我正在使用 Eclipselink 并面临删除问题。我已经ManyToOne
加入如下。
public class UserEntity implements Serializable {
...
@ManyToOne
@JoinColumn(name = "STUDENT_CD", nullable=false)
private StudentEntity student;
}
在尝试删除UserEntity
时,我收到以下异常。
[#|2013-08-07T20:44:52.105+0530|WARNING|glassfish3.1.2|javax.enterprise.resource.jta.com.sun.enterprise.transaction|_ThreadID=35;_ThreadName=Thread-2;|DTX5014: Caught exception in beforeCompletion() callback:
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-01407: cannot update ("SERVICE"."USERS"."STUDENT_CD") to NULL
Error Code: 1407
Call: UPDATE SERVICE.USERS SET STUDENT_CD = ? WHERE (USER_ID = ?)
bind => [null, 1]
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:840)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:906)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:592)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1717)
at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:253)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.updateObject(DatasourceCallQueryMechanism.java:749)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.updateObject(StatementQueryMechanism.java:432)
at org.eclipse.persistence.internal.queries.CallQueryMechanism.updateForeignKeyFieldBeforeDelete(CallQueryMechanism.java:436)
它在这里被称为一个错误。 https://bugs.eclipse.org/bugs/show_bug.cgi?format=multiple&id=341709
该问题出现在 Eclipselink 2.4 中。
有什么建议么?
更新
@Entity
@Table(name = "USER", schema="SERVICE")
public class UserEntity implements Serializable {
...
// bi-directional many-to-one association to StudentEntity
@ManyToOne
@JoinColumn(name = "STUDENT_CD", nullable=false)
private StudentEntity student;
...
}
@Entity
@Table(name = "STUDENT", schema="SERVICE")
public class StudentEntity implements Serializable {
...
@Id
@Column(name = "STUDENT_CD")
private String studentCd;
@OneToMany(mappedBy = "student")
private Set<UserEntity> users;
...
}
我是 JPA 的新手。据我了解,没有循环。