java - Delete fails due to DB exception in updateForeignKeyFieldBeforeDelete -
i using eclipselink , facing issues in delete. have manytoone
join below.
public class userentity implements serializable { ... @manytoone @joincolumn(name = "student_cd", nullable=false) private studententity student; }
while trying delete userentity
, getting below exception.
[#|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") null error code: 1407 call: update service.users set student_cd = ? (user_id = ?) bind => [null, 1] @ org.eclipse.persistence.exceptions.databaseexception.sqlexception(databaseexception.java:324) @ org.eclipse.persistence.internal.databaseaccess.databaseaccessor.executedirectnoselect(databaseaccessor.java:840) @ org.eclipse.persistence.internal.databaseaccess.databaseaccessor.executenoselect(databaseaccessor.java:906) @ org.eclipse.persistence.internal.databaseaccess.databaseaccessor.basicexecutecall(databaseaccessor.java:592) @ org.eclipse.persistence.internal.databaseaccess.databaseaccessor.executecall(databaseaccessor.java:535) @ org.eclipse.persistence.internal.sessions.abstractsession.basicexecutecall(abstractsession.java:1717) @ org.eclipse.persistence.sessions.server.clientsession.executecall(clientsession.java:253) @ org.eclipse.persistence.internal.queries.datasourcecallquerymechanism.executecall(datasourcecallquerymechanism.java:207) @ org.eclipse.persistence.internal.queries.datasourcecallquerymechanism.executecall(datasourcecallquerymechanism.java:193) @ org.eclipse.persistence.internal.queries.datasourcecallquerymechanism.updateobject(datasourcecallquerymechanism.java:749) @ org.eclipse.persistence.internal.queries.statementquerymechanism.updateobject(statementquerymechanism.java:432) @ org.eclipse.persistence.internal.queries.callquerymechanism.updateforeignkeyfieldbeforedelete(callquerymechanism.java:436)
it mentioned bug here. https://bugs.eclipse.org/bugs/show_bug.cgi?format=multiple&id=341709
the issue occurs in eclipselink 2.4.
any suggestions?
update
@entity @table(name = "user", schema="service") public class userentity implements serializable { ... // bi-directional many-to-one association 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; ... }
i new jpa. per understanding there no cycle.
please include full class mappings including relationships, , full sql trace.
eclipselink null foreign key during deletion when detects cycle. i.e. deleting 2 or more objects both reference each other through foreign keys. technically there no way delete model, deletion either side cause foreign key constraint violation.
you may want rethink model not have two-way foreign key dependency. when have bidirectional relationship use "mappedby" on 1 side 1 foreign key used both relationships.
if have cycle, , not-null constraints, may have made data impossible deleted, bad idea. need relax 1 of constraints. if 1 of foreign keys not null , 1 nullable, can set nullable 1 null before deleting objects avoid cycle. can influence side eclipselink nulls using constraintdependency.
you can try 2.5.2 release, take account not null constraints.
Comments
Post a Comment