I have an entity that has a one-to-one relationship:
Whenever I do a conformance.remove(), I get a JDBC Exception:Code:@RooJpaActiveRecord(versionField = "", table = "FD_Conformance") public class Conformance { @NotNull @OneToOne(optional=false, mappedBy = "conformance", orphanRemoval=true, cascade={CascadeType.PERSIST,CascadeType.REMOVE}) private Publisher publisher; ... }
From what I've been able to tell, the problem is that the code is not deleting the Publisher object first and then deleting the conformance object. I have figure out two options, but I don't like either of them:Code:ERROR org.hibernate.util.JDBCExceptionReporter - Cannot delete or update a parent row: a foreign key constraint fails (`HealthFire`.`FD_Publisher`, CONSTRAINT `FK_FD_Publisher_FD_Conformance` FOREIGN KEY (`associated_conformance`) REFERENCES `FD_Conformance` (`conformance_id`))
1) change the foreign key so that it cascades deletes
2) Pull in the remove() method and add code like this:
For the life of me, I've tried to figure out what annotations are needed to get Hibernate to automatically do the deletions. But I can't seem to find anything that will work (you can see that I tried orphanRemoval=true and CascadeType.REMOVE).Code:@Transactional public void remove() { if (this.entityManager == null) this.entityManager = entityManager(); if (this.entityManager.contains(this)) { // this.publisher.remove(); // if (this.implementation != null) { // this.implementation.remove(); // } this.entityManager.remove(this); } else { Conformance attached = Conformance.findConformance(this.Id); // attached.getPublisher().remove(); // if (attached.getImplementation() != null) { // attached.getImplementation().remove(); // } this.entityManager.remove(attached); } }
Is there something simple that I'm not understanding and thus doing wrong?


Reply With Quote