3 Replies Latest reply on Jul 19, 2007 3:18 AM by rapowder

    Cache level

    rapowder

      Hi,

      I'm not sure whether this is the right place to post this question, but I'm not sure either if the problem I have comes from Hibernate or from Seam Conversations.

      I am using seam 1.2.1.GA and hibernate 3.2. In my application, data is updated quite frequently by many concurrent clients. Scenario is very simple. Two pages: one to show items, one to edit an item's properties.

      My item entity is defined as such:

      @Entity
      @Name("item")
      @Table(name="item")
      public class MItem implements Serializable {
      
       @ManyToMany
       @org.hibernate.annotations.Fetch(FetchMode.SUBSELECT)
       @Cascade({
       CascadeType.SAVE_UPDATE,
       CascadeType.MERGE,
       CascadeType.PERSIST})
       @JoinTable(
       name = "item_prop",
       joinColumns = {@JoinColumn(name = "ip_item")},
       inverseJoinColumns = {@JoinColumn(name = "ip_prop")})
       private Set<MProperty> properties = new HashSet<MProperty>();
      
       [...]
      }


      and the property class:

      @Entity
      @Name("property")
      @Table(name="property")
      public class MProperty implements Serializable {
      
       @ManyToMany(mappedBy = "properties")
       private Set<MItem>items = new HashSet<MItem>();
      
       @Column(name = "pr_value")
       private String value;
      
      [...]
      }


      The conversation spans from the item list page to the edit item (join) and is never ended (not even after saving the changes to the item properties).

      If from Client A I update one of the properties of an item I can see my changes in the item list (even without ending the conversation upon persisting) but if from Client B I query the DB I can not see changes done to that property until I logout and login again (or simply when the http session is ended).

      On the contrary, when I create a new item I can see changes on both clients.

      I was not sure weather this was related to the second-level cache of hibernate, which I now disabled but this didn't give any significant results.

      The only solution I found so far is to execute an em.refresh(item) on each item of the list before showing it, which works but has a terrible effect on performances!

      Annotating queries with hints does not work either, does somebody have a good solution for this problem?

      Thank you!


        • 1. Re: Cache level
          ellenzhao

          have you tried to call em.flush() after every update to your entity? And how about do

          item = em.merge(item);

          before you showing the item on UI? Correct me if I'm wrong.

          • 2. Re: Cache level
            rapowder

            I already do both. item = em.merge(item) is what I do after updating item properties and, since I do not end my conversation after saving an item, I execute em.flush() at the end of my "save" method, before rendering the item list.

            • 3. Re: Cache level
              rapowder

              Anyone has other suggestions?