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: Hibernate cache
PostPosted: Wed Sep 19, 2007 3:48 am 

Joined: Wed May 16, 2007 10:45 am
Posts: 2
Dear all,

Hibernate version:3.2.5

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<hibernate-mapping package="com.intralot.bon.entities.config">

   <class name="GameClass" table="GAME_CLASS" discriminator-value="0">
      <cache usage="read-write" />
      <id name="id" column="GAME_CLASS_ID">
         <generator class="sequence">
            <param name="sequence">GAME_CLASS_SEQ</param>
      <discriminator column="GAME_CLASS_TYPE" />
      <version name="version" column="VERSION"/>

      <many-to-one cascade="all" name="name" column="GAME_CLASS_NAME" not-null="true" />
      <many-to-one cascade="all" name="description" column="GAME_CLASS_DSC" not-null="true" />

Named Query:

In an hbm.xml file (Game.hbm.xml) I have the query:

   <query name="getGames">
            GameClass xgc inner join fetch xgc.name inner join fetch xgc.description
            xgc.id = :classId

As you can see in the mapping document, the name and description attributes have many-to-one relationships with other classes.

What I need is to have the name and description in the results that the query will return. The simplest solution to that is to add an attribute lazy="false" in the above two elements in the GameClass.hbm.xml file and to remove the inner join fetches from the query. It works fine.

But, this solution does not harmonize with my project and I need another one. What am I need is to manipulate this task programmatically without the previously referred solution.

Not that I use the ehCache as a second level cache and also when I try to execute the query I use query.setCacheable(true) in order to have the query cacheable.

The problem is that: The first time that the query is executed the results are correct. I get back description and name. But when I try to execute the query again, unfortunately I have no results back. So, the caching of results does not work.

Note that I make a call out of an EJB container to a Session Bean which includes a method that executes the query. This method opens hibernate session, caches the results and then after closing the session, it returns the results to the caller. When I try to recall the same method with the same query (second time), then I get back short results, without the name and description. Maybe, hibernate should realize a join fetch in the cache in order to return the whole results.

Could you please anyone suggest me a solution to that problem?

Many thanks

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.