-->
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.  [ 3 posts ] 
Author Message
 Post subject: problem overriding mapping (disables 2nd level cache) query
PostPosted: Tue Dec 12, 2006 5:47 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
Hibernate version: 3.2

Mapping documents:

<class name="Application" table="APPL_MAIN">
<id name="applicationId" type="long">
<column name="APPLICATION_ID" precision="10" scale="0" />
<generator class="sequence">
<param name="sequence">APPL_MAIN_SEQ</param>
</generator>
</id>
<version name="transactionId" type="integer" unsaved-value="undefined">
<column name="TRANSACTION_ID" precision="8" scale="0"/>
</version>
<property name="applicationType" type="integer">
<column name="APPLICATION_TYPE" precision="8" scale="0" not-null="true" />
</property>
...
<many-to-one name="applicant" class="Applicant"
fetch="select" update="false">
<column name="USER_ID" precision="10" scale="0" not-null="true" />
</many-to-one>

Name and version of the database you are using: Oracle 9i


Both Application and Applicant are defined in the 2nd level cache.

What I'd like to do is override the mapping to retrieve an initialized Applicant using an inner join

eg 1

Application app = (Application) session.load(Application.class, new Long(id));
Hibernate.initialize(app.getApplicant());

- this does NOT perform an inner join

eg 2
"from Application as app inner join fetch app.applicant where app.applicationId = :id"

- this performs the inner join but does NOT use the 2nd level cache (even though I'm selecting by id)


Is this possible without changing the the mapping file?

Many Thanks for the solution


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 6:31 am 
Newbie

Joined: Tue Dec 05, 2006 6:15 pm
Posts: 4
Location: London, England
Quote:
does NOT use the 2nd level cache (even though I'm selecting by id)


Even though you're using an entity Id, you're doing a Criteria/Query search rather than a direct lookup (ie session.load/get). Criteria/Query searches don't read from the 2nd level cache unless you setCacheable(true) on them. and have the QueryCache enabled (see the documentation for details).

Of course this then means that your search will return the exact same results even if applicants have been added/deleted by another process (only an issue if Hibernate doesn't have exclusive use of the relevant tables in the database). At least, until the QueryCache expires (as configured) or some other process comes along and forces a refresh.

Hope this helps,

John

_________________
If you want IT, dowNinja IT.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 7:16 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
Thanks for clarifying, I think I understand:

It would be best to leave fetch="select" as the default, since provided the objects are in the 2nd level cache I dont have a (2nd select) problem anyway...

But if I change to fetch="join" then its not possible to get/load the entity *without* hibernate performing an explicit join to the applicant table.


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