-->
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.  [ 1 post ] 
Author Message
 Post subject: Cached collections use separate cached domain objects
PostPosted: Thu Feb 07, 2008 4:27 am 
Newbie

Joined: Thu Feb 07, 2008 4:06 am
Posts: 1
Hey.

I'm trying to configure cache in main domain applications and I have a small problem (maybe it is a question). I've looked through entire documentation and other sites with tutorials/explanations how second-level cache works in hibernate, but I've found no answers. Here it is...

For example, I have two domain Objects (it's just a simple example, but perfectly describes my problem. In fact my domain objects are a lot more complicated):

Code:
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Order {
   
    @Id
    @GeneratedValue
    Long id;
   
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "order")
    @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
    List<Item> items;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Item> getItems() {
        return items;
    }

    public void setItems(List<Item> items) {
        this.items = items;
    }
   
   
}

@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Item {
    @Id
    @GeneratedValue
    Long id;
   
    @ManyToOne
    @JoinColumn("order_id")
    Order order;

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }
}


Now let's say I would like to load all orders and items (to cache) when my application starts up but I don't want to fetch in one query all orders with fetch join, but I want to load all orders without initializing items collection, then in second query load all items. After that I would like to initialize items collections of all orders for example by calling Hibernate.initialize() on each order's collection (it should initialize them by fetching already cached items).

And there appears my problem, because when I try to initialize items collections that way, hibernate doesn't fetch them from cache (I've already loaded all items to cache). It seems that hibernate uses separate objects in cache for collections... (collection-by-collection and entity-by-entity).

Anyone knows how to workaround this problem ?. Any help would be appreciated.


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

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.