-->
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: CompositeId (embedded) doesn't seem to work with querycache
PostPosted: Thu Nov 04, 2010 2:54 am 
Newbie

Joined: Thu Nov 04, 2010 2:46 am
Posts: 1
I'm having a hard time figuring out how to make effective use of query caching criteria queries on the following entity:

Code:
@Entity @Table(name = "category_configuration_values")
@Immutable
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class CategoryConfigurationValue implements Serializable {
    private static final long serialVersionUID = 3L;
    private static final Logger LOGGER = LoggerFactory.getLogger(CategoryConfigurationValue.class);

    @EmbeddedId
    private CategoryConfigurationValuePk primaryKey;

    @Column(name = "value")
    private String value;

    @Override
    public boolean equals(Object o) { ... }

    @Override
    public int hashCode() { ... }
}

@Embeddable
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
class CategoryConfigurationValuePk implements Serializable {
    private static final long serialVersionUID = 5068893389269876464L;

    @Column(name = "configuration_type_id")
    private int configurationTypeId;

    @Column(name = "category_id", columnDefinition = "smallint")
    private int categoryId;

    @Override
    public int hashCode() { ... }

    @Override
    public boolean equals(Object obj) { ... }

}

The one of the criteria which is resulting in cache misses is:
Code:
    Criteria criteria = getCurrentSession().createCriteria(CategoryConfigurationValue.class);
    criteria.setCacheable(true);
    criteria.setCacheRegion("query.AllConfigurationValuesForCategoriesAndAncestors");
    criteria.add(Restrictions.in("primaryKey.categoryId", categoryIds));

    List<CategoryConfigurationValue> allCategoryConfigurationValues = criteria.list();

The first time is is executed I get the 'in' query:

Code:
Hibernate: select this_.category_id as category1_4_0_, this_.configuration_type_id as configur2_4_0_, this_.value as value4_0_ from category_configuration_values this_ where this_.category_id in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)


If I execute it another time I get a lot of the following, which to me looks like cache misses:

Code:
    Hibernate: select categoryco0_.category_id as category1_4_0_, categoryco0_.configuration_type_id as configur2_4_0_, categoryco0_.value as value4_0_ from category_configuration_values categoryco0_ where categoryco0_.category_id=? and categoryco0_.configuration_type_id=?
Hibernate: select categoryco0_.category_id as category1_4_0_, categoryco0_.configuration_type_id as configur2_4_0_, categoryco0_.value as value4_0_ from category_configuration_values categoryco0_ where categoryco0_.category_id=? and categoryco0_.configuration_type_id=?
Hibernate: select categoryco0_.category_id as category1_4_0_, categoryco0_.configuration_type_id as configur2_4_0_, categoryco0_.value as value4_0_ from category_configuration_values categoryco0_ where categoryco0_.category_id=? and categoryco0_.configuration_type_id=?
Hibernate: select categoryco0_.category_id as category1_4_0_, categoryco0_.configuration_type_id as configur2_4_0_, categoryco0_.value as value4_0_ from category_configuration_values categoryco0_ where categoryco0_.category_id=? and categoryco0_.configuration_type_id=?
Hibernate: select categoryco0_.category_id as category1_4_0_, categoryco0_.configuration_type_id as configur2_4_0_, categoryco0_.value as value4_0_ from category_configuration_values categoryco0_ where categoryco0_.category_id=? and categoryco0_.configuration_type_id=?
...


Query caches work for objects without composit ids. What could I be missing here?


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.