java - The DELETE statement conflicted with the REFERENCE constraint. Even though the correct mapping is used -


i have code in .net application:

public grademapper()         {             totable("grades");              // primary key             haskey(c => c.gradeid);              // properties              //relations             hasoptional(g => g.determinatetableprop).withmany().map(m => m.mapkey("determinatetableid")).willcascadeondelete(false);         } 

in database have this:

database contents

i'm using javafx application make adjustments database. want delete determinatetable, not grade belongs to.

this code use delete it:

public void deletedeterminatetablebyid(int id){         em.gettransaction().begin();         em.remove(finddeterminatetablebyid(id));         em.gettransaction().commit();     } 

but error:

caused by: exception [eclipselink-4002] (eclipse persistence services - 2.6.0.v20141202-3914740): org.eclipse.persistence.exceptions.databaseexception internal exception: com.microsoft.sqlserver.jdbc.sqlserverexception: delete statement conflicted reference constraint "fk_dbo.grades_dbo.determinatetable_determinatetableid". conflict occurred in database "hogent1415_11", table "dbo.grades", column 'determinatetableid'. error code: 547 call: delete determinatetable (determinatetableid = ?)     bind => [1 parameter bound] query: deleteobjectquery(domain.determinatetable@ee66dbe) 

so wrong mapping? want foreign key in grade table set null when determinate table deleted.

you have foreign key on table can set cascade delete, , update, solve issue when delete parent have child.