2 Replies Latest reply on Jul 22, 2010 8:04 PM by 786610

    HibernateCacheStore - Cascade deletes

    777989
      Hello,
      We are using the HibernateCacheStore as the cacheStore for some entities. One of the entities has a list of children (one to many relationship). The cascade options have been specified correctly. When we call cache.remove on the parent entity, we get constraint violation exceptions. Upon inspecting the sql being generated, it seems that delete for the child entities is not being executed. If we bypass coherence and just use hibernate to delete, the entities get deleted successfully.

      Does the HibernateCacheStore not handle cascade deletes?

      Thanks
      Vaibhav
        • 1. Re: HibernateCacheStore - Cascade deletes
          bobhanckel-Oracle
          Could you give info on what you are seeing in SQL to identify the children
          that are being deleted from the table? i.e. the WHERE clause.
          • 2. Re: HibernateCacheStore - Cascade deletes
            786610
            Hi,
            I'm working with VG on this problem. Here is what we've got.

            Below are the mappings we're using (I omitted most of the surrounding code and fields which are not relevant for this issue), and the SQL we get from hibernate, both when using and not using the cache for the delete.

            The object does get deleted if we do not use the cache to remove it. However, if we get the object from the cache and then use it directly on our generic hibernate dao to delete, it does work (but this leaves the cached object still in the cache, since we bypassed it).

            Mappings

            Parent class:
            public class Bottle implements Serializable {
                 ...
            @OneToMany(mappedBy = "bottle", fetch = FetchType.EAGER)
            @Cascade({CascadeType.DELETE_ORPHAN, CascadeType.ALL})
            public List<BottleComment> comments;
                 ...


            Child class:
            public class BottleComment implements Serializable {
                 ...
            @ManyToOne(targetEntity = Bottle.class)
            @JoinColumn(name="BOTTLE_ID", nullable = false)
            private Bottle bottle;
                 ...
                 


            SQL, With Cache enabled (we get an error, does not delete):

            2010-07-20 21:00:21,296 [DistributedCache] DEBUG org.hibernate.SQL
            select bottle_.BOTTLE_ID, bottle_.CHANGE_DATE as CHANGE2_44_, ... from USER_BOTTLE bottle_ where bottle_.BOTTLE_ID=?

            2010-07-20 21:00:21,312 [DistributedCache] DEBUG org.hibernate.SQL
            delete from USER_BOTTLE where BOTTLE_ID=?

            2010-07-20 21:00:21,453 [DistributedCache] WARN org.hibernate.util.JDBCExceptionReporter
            SQL Error: 2292, SQLState: 23000

            2010-07-20 21:00:21,453 [DistributedCache] ERROR org.hibernate.util.JDBCExceptionReporter
            ORA-02292: integrity constraint (ID_DSP26.UB_UBC_BOTTLE_ID_FK1) violated - child record found


            SQL, Bypassing the cache (this works!):

            2010-07-20 20:54:34,843 [TP-Processor3] DEBUG org.hibernate.SQL
            select bottle_.BOTTLE_ID, bottle_.CHANGE_DATE as CHANGE2_44_, ... from USER_BOTTLE bottle_ where bottle_.BOTTLE_ID=?

            2010-07-20 20:54:34,859 [TP-Processor3] DEBUG org.hibernate.SQL
            select bottlecomm_.BOTTLE_COMMENT_ID, ... bottlecomm_.BOTTLE_ID as BOTTLE4_45_ from USER_BOTTLE_COMMENT bottlecomm_     where bottlecomm_.BOTTLE_COMMENT_ID=?

            2010-07-20 20:54:34,875 [TP-Processor3] DEBUG org.hibernate.SQL
            delete from USER_BOTTLE_COMMENT where BOTTLE_COMMENT_ID=?

            2010-07-20 20:54:34,921 [TP-Processor3] DEBUG org.hibernate.SQL
            delete from USER_BOTTLE where BOTTLE_ID=?



            The main difference seems to be that the cache simply ignores and does not query for the bottle_comments, while using hibernate directly does.

            Any help would be greatly appreciated.

            Thanks,
            Jorge