-->
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.  [ 6 posts ] 
Author Message
 Post subject: Cache & Proxy management
PostPosted: Wed Apr 07, 2004 11:39 am 
Regular
Regular

Joined: Tue Oct 07, 2003 1:13 pm
Posts: 70
Location: Paris, France
Hibernate : 2.1.2
Cache : ehcache0.6

Hi,
I cant understand why when I load (session.load()) a com.company.Dossier instance, a sql query is done to retrieve the com.company.Raitance associated instance. I am expecting Hibernate doesn't hit the database because com.company.Raitance instance must be a proxy ! Am i wrong ?

Thank you for your help
Richard.

<class
name="com.company.Dossier"
table="dossier"
dynamic-update="true"
dynamic-insert="true"
>
<cache usage="read-write" />

...

<many-to-one
name="raitance"
class="com.company.Raitance"
cascade="all"
outer-join="auto"
update="true"
insert="true"
column="raitance_id"
unique="true"
/>

...
</class>

<class
name="com.company.Raitance"
table="maltraitance"
proxy="com.company.Raitance"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="assigned">
</generator>
</id>

<property
name="commentairesApresEvaluation"
type="string"
>
<column
name="comment_apres_eval"
sql-type="text"
/>
</property>

<array
name="consequences"
table="consequence"
inverse="false"
cascade="none"
>

<key
column="conseq_id"
/>

<index
column="indice"
/>

<many-to-many
class="com.company.Consequence"
column="tm_id"
outer-join="auto"
/>

</array>

</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 8:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It should work.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 9:14 am 
Regular
Regular

Joined: Tue Oct 07, 2003 1:13 pm
Posts: 70
Location: Paris, France
I agree, it should work.
I'm very surprised when analyzing the trace and the result of the session.load() :
1/ My object is correctly initialized, the many-to-one is a proxy :

result= Dossier (id=221)
appelant= Raitance$$EnhancerByCGLIB$$c96c2d05 (id=225)

2/ Here is the relevant hibernate trace :

08-04-2004 14:06:18:608 DEBUG net.sf.hibernate.impl.SessionImpl:531 - opened session
08-04-2004 14:06:18:628 DEBUG net.sf.hibernate.impl.SessionImpl:1950 - loading [com.uniclick.afbah.modele.dossier.Dossier#409]
08-04-2004 14:06:18:638 DEBUG net.sf.hibernate.impl.SessionImpl:2047 - attempting to resolve [com.uniclick.afbah.modele.dossier.Dossier#409]
08-04-2004 14:06:18:658 DEBUG net.sf.hibernate.cache.ReadWriteCache:68 - Cache lookup: 409
08-04-2004 14:06:18:658 DEBUG net.sf.hibernate.cache.ReadWriteCache:78 - Cache hit: 409
08-04-2004 14:06:18:668 DEBUG net.sf.hibernate.impl.SessionImpl:2092 - resolved object in second-level cache [com.uniclick.afbah.modele.dossier.Dossier#409]
...
08-04-2004 14:06:19:650 DEBUG net.sf.hibernate.impl.SessionImpl:1950 - loading [com.uniclick.afbah.modele.dossier.raitance.Raitance#409]
08-04-2004 14:06:19:660 DEBUG net.sf.hibernate.impl.SessionImpl:1950 - loading [com.uniclick.afbah.modele.dossier.maltraitance.Maltraitance#409]
08-04-2004 14:06:19:680 DEBUG net.sf.hibernate.impl.SessionImpl:3891 - creating collection wrapper:[com.uniclick.afbah.modele.dossier.Dossier.victimes#409]
08-04-2004 14:06:19:690 DEBUG net.sf.hibernate.impl.SessionImpl:3891 - creating collection wrapper:[com.uniclick.afbah.modele.dossier.Dossier.maltraitants#409]
08-04-2004 14:06:19:700 DEBUG net.sf.hibernate.impl.SessionImpl:3891 - creating collection wrapper:[com.uniclick.afbah.modele.dossier.Dossier.suivis#409]
08-04-2004 14:06:19:710 DEBUG net.sf.hibernate.impl.SessionImpl:2047 - attempting to resolve [com.uniclick.afbah.modele.dossier.raitance.Raitance#409]
08-04-2004 14:06:19:720 DEBUG net.sf.hibernate.impl.SessionImpl:2080 - object not resolved in any cache [com.uniclick.afbah.modele.dossier.raitance.Raitance#409]
08-04-2004 14:06:19:730 DEBUG net.sf.hibernate.persister.EntityPersister:416 - Materializing entity: [com.uniclick.afbah.modele.dossier.raitance.Raitance#409]
08-04-2004 14:06:19:740 DEBUG net.sf.hibernate.impl.BatcherImpl:196 - about to open: 0 open PreparedStatements, 0 open ResultSets
08-04-2004 14:06:19:750 DEBUG net.sf.hibernate.SQL:237 - select raitance0_.id as id0_, raitance0_.adresse as adresse0_, raitance0_.age as age0_, raitance0_.code_postal as code_pos4_0_, raitance0_.contacte_direct as contacte5_0_, raitance0_.nom as nom0_, raitance0_.prenom as prenom0_, raitance0_.profession_id as professi8_0_, raitance0_.relation_victime as relation9_0_, raitance0_.sexe as sexe0_, raitance0_.situation_familiale as situati11_0_, raitance0_.tel_bur as tel_bur0_, raitance0_.tel_dom as tel_dom0_, raitance0_.tel_port as tel_port0_, raitance0_.civilite as civilite0_, raitance0_.ville as ville0_, raitance0_.commentaires as comment17_0_ from raitance raitance0_ where raitance0_.id=?
Hibernate: select raitance0_.id as id0_, raitance0_.adresse as adresse0_, raitance0_.age as age0_, raitance0_.code_postal as code_pos4_0_, raitance0_.contacte_direct as contacte5_0_, raitance0_.nom as nom0_, raitance0_.prenom as prenom0_, raitance0_.profession_id as professi8_0_, raitance0_.relation_victime as relation9_0_, raitance0_.sexe as sexe0_, raitance0_.situation_familiale as situati11_0_, raitance0_.tel_bur as tel_bur0_, raitance0_.tel_dom as tel_dom0_, raitance0_.tel_port as tel_port0_, raitance0_.civilite as civilite0_, raitance0_.ville as ville0_, raitance0_.commentaires as comment17_0_ from raitance raitance0_ where raitance0_.id=?
08-04-2004 14:06:19:770 DEBUG net.sf.hibernate.impl.BatcherImpl:241 - preparing statement
08-04-2004 14:06:19:780 DEBUG net.sf.hibernate.type.LongType:46 - binding '409' to parameter: 1
08-04-2004 14:06:19:800 DEBUG net.sf.hibernate.loader.Loader:197 - processing result set
08-04-2004 14:06:19:830 DEBUG net.sf.hibernate.loader.Loader:405 - result row: 409
08-04-2004 14:06:19:840 DEBUG net.sf.hibernate.loader.Loader:536 - Initializing object from ResultSet: 409
08-04-2004 14:06:19:850 DEBUG net.sf.hibernate.loader.Loader:605 - Hydrating entity: com.uniclick.afbah.modele.dossier.raitance.Raitance#409
08-04-2004 14:06:19:870 DEBUG net.sf.hibernate.type.StringType:68 - returning '54 rue d'alouette' as column: adresse0_
08-04-2004 14:06:19:880 DEBUG net.sf.hibernate.type.PersistentEnumType:68 - returning '7' as column: age0_
08-04-2004 14:06:19:890 DEBUG net.sf.hibernate.type.StringType:68 - returning '75012' as column: code_pos4_0_
08-04-2004 14:06:19:900 DEBUG net.sf.hibernate.type.PersistentEnumType:68 - returning '0' as column: contacte5_0_
08-04-2004 14:06:19:910 DEBUG net.sf.hibernate.type.StringType:68 - returning 'DUPONT' as column: nom0_
08-04-2004 14:06:19:930 DEBUG net.sf.hibernate.type.StringType:68 - returning 'Bertrand' as column: prenom0_
08-04-2004 14:06:19:940 DEBUG net.sf.hibernate.type.LongType:68 - returning '1' as column: professi8_0_
08-04-2004 14:06:19:950 DEBUG net.sf.hibernate.type.LongType:68 - returning '1' as column: relation9_0_
08-04-2004 14:06:19:960 DEBUG net.sf.hibernate.type.PersistentEnumType:68 - returning '1' as column: sexe0_
08-04-2004 14:06:19:970 DEBUG net.sf.hibernate.type.PersistentEnumType:68 - returning '0' as column: situati11_0_
08-04-2004 14:06:19:990 DEBUG net.sf.hibernate.type.StringType:68 - returning '0178124578' as column: tel_bur0_
08-04-2004 14:06:20:000 DEBUG net.sf.hibernate.type.StringType:68 - returning '0141547896' as column: tel_dom0_
08-04-2004 14:06:20:010 DEBUG net.sf.hibernate.type.StringType:68 - returning '0678651245' as column: tel_port0_
08-04-2004 14:06:20:030 DEBUG net.sf.hibernate.type.PersistentEnumType:68 - returning '1' as column: civilite0_
08-04-2004 14:06:20:040 DEBUG net.sf.hibernate.type.StringType:68 - returning 'PARIS' as column: ville0_
08-04-2004 14:06:20:060 DEBUG net.sf.hibernate.type.StringType:68 - returning 'bonjour


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 09, 2004 3:33 am 
Regular
Regular

Joined: Tue Oct 07, 2003 1:13 pm
Posts: 70
Location: Paris, France
Can it be considered as a bug ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 09, 2004 3:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
dharma wrote:
Can it be considered as a bug ?


Yes. A bug in your code. Use your debugger.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 10, 2004 6:29 am 
Regular
Regular

Joined: Tue Oct 07, 2003 1:13 pm
Posts: 70
Location: Paris, France
Bashed !! :-)
Sorry, it was my fault, when hibernate sets the many-to-one association, I enforce a setId in the setter method (one-to-one turned into many-to-one), so hibernate hits the db to retrieve the association.


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