Hi guys hope you are doing good. 

 

Our product was developed by using hibernate as JPA provider. But now we are
moving to OpenJPA. We are able to move forward in most of the uses cases.
But we are finding difficulty on entity delete use cases. 

My requirement is when I delete parent entity, parent and it's child
collection objects should be deleted. But I am getting constraint violation
exception. 

This code was working fine with hibernate. Can you please help me how to
resolve this issue. Please find  entity definitions and code to delete the
entity below

 

I have already tried all the suggestions found in google. But no luck L

 

Code to delete the entity:

 

        private final HookRepository hookRepository; //Auto wired

        final Hook hook = this.hookRepository.findOne(hookId); //Retrieving
Hook Entity from repository

        this.hookRepository.delete(hook);

 

Entity Definitions are below:

 

@Entity

@Table(name = "m_hook")

public class Hook extends AbstractAuditableCustom<AppUser, Long> {

 

    @Column(name = "name", nullable = false, length = 100)

    private String name;

 

    @Column(name = "is_active", nullable = false)

    private Boolean isActive;

 

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "hook", orphanRemoval =
true, fetch=FetchType.EAGER)

    private Set<HookResource> events = new HashSet<>();

 

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "hook", orphanRemoval =
true, fetch=FetchType.EAGER)

    private Set<HookConfiguration> config = new HashSet<>();

 

    @ManyToOne(optional = true)

    @JoinColumn(name = "template_id", referencedColumnName = "id", nullable
= false)

    private HookTemplate template;

 

    @ManyToOne(optional = true)

    @JoinColumn(name = "ugd_template_id", referencedColumnName = "id",
nullable = true)

    private Template ugdTemplate;

 

    protected Hook() {

        //

    }

}

 

@Entity

@Table(name = "m_hook_registered_events")

public class HookResource extends AbstractPersistableCustom<Long> {

 

       @ManyToOne(optional = false)

       @JoinColumn(name = "hook_id", referencedColumnName = "id", nullable =
false)

       private Hook hook;

 

       @Column(name = "entity_name", nullable = false, length = 45)

       private String entityName;

 

       @Column(name = "action_name", nullable = false, length = 45)

       private String actionName;

 

}

 

@Entity

@Table(name = "m_hook_configuration")

public class HookConfiguration extends AbstractPersistableCustom<Long> {

 

       @ManyToOne(optional = false)

       @JoinColumn(name = "hook_id", referencedColumnName = "id", nullable =
false)

       private Hook hook;

 

       @Column(name = "field_type", nullable = false, length = 20)

       private String fieldType;

 

       @Column(name = "field_name", nullable = false, length = 100)

       private String fieldName;

 

       @Column(name = "field_value", nullable = false, length = 100)

       private String fieldValue;

 

}

 

Thanks,

Nazeer

Reply via email to