Announcement Announcement Module
No announcement yet.
@RooJpaActiveRecord remove() method (perhaps missing JPA annotation?) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @RooJpaActiveRecord remove() method (perhaps missing JPA annotation?)

    I have an entity that has a one-to-one relationship:

    @RooJpaActiveRecord(versionField = "", table = "FD_Conformance")
    public class Conformance {
        @OneToOne(optional=false, mappedBy = "conformance", orphanRemoval=true, cascade={CascadeType.PERSIST,CascadeType.REMOVE})
        private Publisher publisher;
    Whenever I do a conformance.remove(), I get a JDBC Exception:
    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`))
    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:
    1) change the foreign key so that it cascades deletes
    2) Pull in the remove() method and add code like this:
        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();
    //        	}
            } else {
                Conformance attached = Conformance.findConformance(this.Id);
    //            attached.getPublisher().remove();
    //        	if (attached.getImplementation() != null) {
    //        		attached.getImplementation().remove();
    //        	}
    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).

    Is there something simple that I'm not understanding and thus doing wrong?