-->
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.  [ 2 posts ] 
Author Message
 Post subject: FetchMode.SELECT not working?
PostPosted: Thu May 04, 2006 10:29 am 
Newbie

Joined: Tue Mar 09, 2004 11:17 pm
Posts: 8
I have a Role entity which has a many-to-one relationship into a Group entity. Since roles and groups are seldom changed, I wanted to implement a cache strategy for when retrieving a list of all roles with its groups.
Both entities are cacheable, so I thought to use the criteria query below, thinking that the main select will retrieve all the roles, and then when trying to retrieve every group, they would be picked-up from 2nd level cache (or SELECTed if it's not there yet).

However, no SELECT is executed after the main one, nor the groups got from the cache, Hibernate simply places a proxy for every group, and my app crashes when tries to show the list on screen. Please see the log excerpt to confirm this.

If I use FetchMode.JOIN instead of FetchMode.SELECT, an INNER JOIN is generated and everything works, but I understand this is not so efficient in terms of cache usage.

Am I doing something wrong, forgetting anything, or is this a bug?

Thanks,
Alex.



Hibernate version:
3.1.2
Annotations 3.1.0 beta 8

Mapping documents:
Code:
@Entity
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MutableRole implements Role {

     ...

    @ManyToOne(targetEntity=MutableGroup.class, fetch=FetchType.LAZY)
    @JoinColumn(name="GROUP_TYPE_ID", nullable=false)
   public Group getGroup() {
      return group;
   }
}
@Entity
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MutableGroup implements Group {
     ...
}


Code between sessionFactory.openSession() and session.close():
Code:
roles = session.createCriteria(MutableRole.class).setFetchMode("group", FetchMode.SELECT).list();


Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 10g

The generated SQL (show_sql=true):
Code:
Hibernate: /* criteria query */ select this_.id as id8_0_, this_.name as name8_0_, this_.description as descript4_8_0_, this_.GROUP_TYPE_ID as GROUP5_8_0_, this_.ROLE_TYPE as ROLE1_8_0_ from ROLES this_

Debug level Hibernate log excerpt:

Code:
182771 [http-8080-2] DEBUG org.hibernate.engine.TwoPhaseLoad  - resolving associations for [tv.nation217.phoenix.model.impl.MutablePhoenixRole#81]
182771 [http-8080-2] DEBUG org.hibernate.engine.CollectionLoadContext  - creating collection wrapper:[tv.nation217.phoenix.model.impl.MutableRole.permissions#81]
182771 [http-8080-2] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - loading entity: [tv.nation217.phoenix.model.impl.MutableGroup#81]
182771 [http-8080-2] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - creating new proxy for entity
182771 [http-8080-2] DEBUG org.hibernate.engine.TwoPhaseLoad  - adding entity to second-level cache: [tv.nation217.phoenix.model.impl.MutablePhoenixRole#81]
182771 [http-8080-2] DEBUG org.hibernate.cache.NonstrictReadWriteCache  - Caching: tv.nation217.phoenix.model.impl.MutableRole#81
182771 [http-8080-2] DEBUG org.hibernate.engine.TwoPhaseLoad  - done materializing entity [tv.nation217.phoenix.model.impl.MutablePhoenixRole#81]


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 11:21 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
With a similar query as yours, the following code is working fine for me. I mean, when I access Group related information - a second query is being executed as can be seen from logs.

Code:
Criteria c = session.createCriteria( Role.class );
c.setFetchMode( "group", FetchMode.SELECT );
List roles = c.list();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.