-->
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: Detach an object related with a many-to-one association ?
PostPosted: Tue Feb 28, 2006 4:37 am 
Newbie

Joined: Fri Oct 28, 2005 9:08 am
Posts: 12
I have a many-to-one association. When I get the first object, I evict it from the session (I use session.clear() to evict all objects). Because I set lazy="no-proxy" for the association, the object associated is not loaded. I want to use my service to populate the associated object but I have some difficulties because hibernate initializes a proxy on it and load the object from database when I use setter methods on this object. (I use hibernate 3.1.2)

-------------------------------------------------------

Here are the mapping files :

<hibernate-mapping package="com.cwsoft.commons.model.businessobject">
<class name="Ccd01" table="CCD01">
<id name="numcpt" type="java.lang.String" column="NUMCPT" >
<generator class="assigned"/>
</id>
<property name="numcli" column="NUMCLI" type="string"/>
<many-to-one name="typcpt" column="TYPCPT" class="Tad01" lazy="no-proxy" cascade="evict"/>
</class>
</hibernate-mapping>

<hibernate-mapping package="com.cwsoft.commons.model.businessobject">
<class name="Tad01" table="TAD01">
<id name="argtbl" type="java.lang.String" column="ARGTBL" >
<generator class="assigned"/>
</id>
<property name="numtbl" type="string" column="NUMTBL" />
<property name="libel1_1" column="LIBEL1_1" type="string" />
</class>
</hibernate-mapping>

----------------------------------------------------------------------

And the test :

Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();

Ccd01 ccd01 = (Ccd01)session.get(Ccd01.class,"999000000171");
session.clear();
Tad01 tad01 = ccd01.getTypcpt();
System.out.println("jba argtbl "+tad01.getArgtbl());
System.out.println("jba setNum");
tad01.setNumtbl("300");
System.out.println("jba setNum is set");

tx.commit();
HibernateUtil.closeSession();

-----------------------------------------------------------------------

And here are the logs between System.out.println("jba argtbl "+tad01.getArgtbl()); and System.out.println("jba setNum is set");

jba argtbl 01
jba setNum
5328 ms DEBUG org.hibernate.impl.SessionImpl - initializing proxy: [com.cwsoft.commons.model.businessobject.Tad01#01]
5328 ms DEBUG org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [com.cwsoft.commons.model.businessobject.Tad01#01]
5328 ms DEBUG org.hibernate.event.def.DefaultLoadEventListener - object not resolved in any cache: [com.cwsoft.commons.model.businessobject.Tad01#01]
5328 ms DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Fetching entity: [com.cwsoft.commons.model.businessobject.Tad01#01]
5328 ms DEBUG org.hibernate.loader.Loader - loading entity: [com.cwsoft.commons.model.businessobject.Tad01#01]
5328 ms DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
5328 ms DEBUG org.hibernate.SQL - select tad01x0_.ARGTBL as ARGTBL2_0_, tad01x0_.NUMTBL as NUMTBL2_0_, tad01x0_.LIBEL1_1 as LIBEL3_2_0_ from TAD01 tad01x0_ where tad01x0_.ARGTBL=?
Hibernate: select tad01x0_.ARGTBL as ARGTBL2_0_, tad01x0_.NUMTBL as NUMTBL2_0_, tad01x0_.LIBEL1_1 as LIBEL3_2_0_ from TAD01 tad01x0_ where tad01x0_.ARGTBL=?
5328 ms DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
5343 ms DEBUG org.hibernate.type.StringType - binding '01' to parameter: 1
5359 ms DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
5359 ms DEBUG org.hibernate.loader.Loader - processing result set
5359 ms DEBUG org.hibernate.loader.Loader - result set row: 0
5359 ms DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.cwsoft.commons.model.businessobject.Tad01#01]
5359 ms DEBUG org.hibernate.loader.Loader - Initializing object from ResultSet: [com.cwsoft.commons.model.businessobject.Tad01#01]
5359 ms DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Hydrating entity: [com.cwsoft.commons.model.businessobject.Tad01#01]
5359 ms DEBUG org.hibernate.type.StringType - returning '400' as column: NUMTBL2_0_
5359 ms DEBUG org.hibernate.type.StringType - returning 'test' as column: LIBEL3_2_0_
5374 ms DEBUG org.hibernate.loader.Loader - done processing result set (1 rows)
5374 ms DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
5374 ms DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
5374 ms DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
5374 ms DEBUG org.hibernate.loader.Loader - total objects hydrated: 1
5374 ms DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [com.cwsoft.commons.model.businessobject.Tad01#01]
5374 ms DEBUG org.hibernate.engine.TwoPhaseLoad - done materializing entity [com.cwsoft.commons.model.businessobject.Tad01#01]
5374 ms DEBUG org.hibernate.engine.StatefulPersistenceContext - initializing non-lazy collections
5374 ms DEBUG org.hibernate.loader.Loader - done entity load
jba setNum is set


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.