-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Ehcache Question and Collection Question
PostPosted: Wed Dec 10, 2003 8:45 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
Hi alls,
I'm using 2.1rc from CVS and Ehcache provider.
I have such class

Code:
/**
* @hibernate.class table="feedback_category"
* mutable="true" dynamic-update="true"
* @hibernate.jcs-cache usage="read-write"
*/
public class FeedbackCategory {
.....
/**
   * @return
   * @hibernate.bag inverse="true"
   * table="feedback_category"
   * lazy="false"
   * cascade="all"
   * order-by="position"
   * @hibernate.jcs-cache usage="read-write"
   * @hibernate.collection-key column="fee_category_id"
   * @hibernate.collection-one-to-many class="com.clearview.feedback.db.report.FeedbackCategory"
   */
  public List getChildren() {
    return children;
  }

  public void setChildren(List children) {
    this.children = children;
  }

   /**
   * @return
   * @hibernate.property column="position"
   * not-null="true"
   * unique="false"
   */
  public int getPosition() {
    return position;
  }

  public void setPosition(int position) {
    this.position = position;
  }
............
}


When i change position in root category, than changes are seen. But when i change position in child, than changes are seen in DB, but aren't seen in Hibernate. I can make it working only disabling hibernate.jcs-cache on children collection.

Is it possible caching colelction and when data are changed, user can see it too.

Thank's


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 8:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You must modify *both* ends of the bidirectional association.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 9:23 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
gavin wrote:
You must modify *both* ends of the bidirectional association.

I do it.
Code:
....
for (int i = 0; i < categories.size() && !isFound; i++) {
  FeedbackCategory category = (FeedbackCategory) categories.get(i);
  if (current.equals(category)) {
    if (isUp)
      movedCategory = (FeedbackCategory) categories.get(i - 1);
     else
       movedCategory = (FeedbackCategory) categories.get(i + 1);
     int position = movedCategory.getPosition();
     movedCategory.setPosition(current.getPosition());
     current.setPosition(position);
     isFound = true;
  }
}
if (isFound) {
  session.beginTransaction();
  session.saveOrUpdate(current);
  session.saveOrUpdate(movedCategory);
  if (current.getParent() != null) {
    session.saveOrUpdate(current.getParent());
  }
  session.commit();
}
...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 9:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I don't believe you. Enable the Hibernate debug-level log, where it will show you all the collections that are found to be dirty (and hence updated in the cache).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 10:31 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
gavin wrote:
I don't believe you. Enable the Hibernate debug-level log, where it will show you all the collections that are found to be dirty (and hence updated in the cache).


Yes, you're right. The changes are in cache too. But as you can see in this collection i use SQL ordering.

Code:
/**
   * @return
   * @hibernate.bag inverse="true"
   * table="feedback_category"
   * lazy="false"
   * cascade="all"
   * order-by="position"
   * @hibernate.jcs-cache usage="read-write"
   * @hibernate.collection-key column="fee_category_id"
   * @hibernate.collection-one-to-many class="com.clearview.feedback.db.report.FeedbackCategory"
   */
  public List getChildren() {
    return children;
  }


After updating position there're updated children but with the same ordering in cache. So i think i have to migrate to set from bag :( bad news...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 10:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ummmm actually collections are only re-added to the cache after they are freshly retrieved from the db ... so I don't think this is correct.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.