Announcement Announcement Module
Collapse
No announcement yet.
@RooJpaActiveRecord remove() method (perhaps missing JPA annotation?) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    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;
    
    ...
    }
    Whenever I do a conformance.remove(), I get a JDBC Exception:
    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`))
    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:
    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);
            }
        }
    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?
Working...
X