-->
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: OneToMany second level caching dehydratation behavior
PostPosted: Thu Jan 14, 2010 11:36 am 
Newbie

Joined: Fri Jun 16, 2006 11:20 am
Posts: 8
Hi,

I'm having a (I think) an unusual behavior of 2nd-level caching when a Set is annotated with @OneToMany.

This is the case:

Main entity, Hotel:
Code:
@Entity
@Table(name = "HOTEL")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include = "all")
public class Hotel extends AbstractPersistentObjectWithLogicalDeletion {
...
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "HOTEL_OID", nullable = false)
    @ForeignKey(name = "FK_PICTURE__HOTEL")
    @Index(name = "IDX_PICTURE__HOTEL_OID")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include = "all")
    public Set<Picture> getPictures() {
        if (this.pictures == null) {
            this.pictures = new HashSet<Picture>();
        }
        return this.pictures;
    }

...
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "HOTEL_PAYMENT_MEAN", joinColumns = @JoinColumn(name = "HOTEL_OID"), inverseJoinColumns = @JoinColumn(name = "PAYMENT_MEAN_OID"))
    @ForeignKey(name = "FK_HOTEL__HOTEL_PAYMENT_MEAN", inverseName = "FK_PAYMENT_MEAN__HOTEL_PAYMENT_MEAN")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include = "all")
    public Set<PaymentMean> getPaymentMean() {
        if (this.paymentMean == null) {
            this.paymentMean = new HashSet<PaymentMean>();
        }
        return this.paymentMean;
    }
...
}


OneToMany child entity, Picture:
Code:
@Entity
@Table(name = "PICTURE")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include = "all")
public class Picture extends AbstractPersistentObject {
...
}


ManyToMany child entity, PaymentMean:
Code:
@Entity
@Table(name = "PAYMENT_MEAN")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
public abstract class PaymentMean extends AbstractPersistentObjectWithLogicalDeletion {
...
}


I'm using a 2nd level cache implementation that stores the data on memcached servers, so if the object gets too dehydrated, it takes up to 106 cache-puts in the memcached (average). The point is that with this approach, enabling memcached as 2nd level duplicates the response time that I get with 2nd level disabled, I mean, going to the db every time.

After I clear the cache and seeing that the keys stored in the cache are the following:

Code:
set> com.despegar.hotel.model.Hotel:0:358
set> com.despegar.hotel.model.Hotel.paymentMean:0:358
set> com.despegar.hotel.model.Picture:0:3531
set> com.despegar.hotel.model.Picture:0:3532
set> com.despegar.hotel.model.Hotel.pictures:0:358


Now, the questions...
- Why is storing the 2 records of paymentMean in one single object and pictures doesn't?
- Is there a Loader / Persister hint/annotation I can set to change this behavior?
- Am I totally wrong and this a expected and unmodifiable behavior?

Thanks in advance!
German Kondolf


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.