-->
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.  [ 5 posts ] 
Author Message
 Post subject: Load a lazy attribute
PostPosted: Mon Jan 02, 2006 6:02 am 
Newbie

Joined: Tue Aug 09, 2005 7:02 pm
Posts: 7
Hibernate version: 3.0.5

Mapping documents:
Code:
    <class name="Module" table="c_mod_v2">
         <composite-id>
           <key-property name="ModNo" column="mod_no" type="java.lang.Integer"/>
           <key-property name="ClientBpCd" column="client_bp_cd" type="java.lang.String" />
           <key-property name="ClientOdsCd" column="client_ods_cd" type="java.lang.String" />
        </composite-id>
        <property name="ChainNb" column="chain_nb" type="java.lang.String" />
        <property name="ClustNb" column="clust_nb" type="java.lang.String" />
        <property name="ModClstCd" column="mod_clst_cd" type="java.lang.String" />       
        <property name="ModNm" column="mod_nm" type="java.lang.String"  not-null="true" />
        <property name="ModTyCd" column="mod_ty_cd" type="java.lang.String" />               
        <property name="NbSlots" column="nb_slots" type="java.lang.Integer" />
        <property name="RackNo" column="rack_no" type="java.lang.Integer"  not-null="true" lazy="true"/>
        <property name="CUid" column="c_uid" type="java.lang.String"  not-null="true" lazy="true" />
        <property name="CDt" column="c_dt" type="java.util.Date"  not-null="true" lazy="true" />
        <property name="UUid" column="u_uid" type="java.lang.String" lazy="true"/>
        <property name="UDt" column="u_dt" type="java.util.Date" lazy="true"/>
        <property name="SusyTxCd" column="susy_tx_cd" type="java.lang.String" lazy="true"/>
        <property name="RecStat" column="rec_stat" type="java.lang.Short"  not-null="true" lazy="true"/>
    </class>


In rare occasions I would like to also load the attributes which are specified with lazy="true". Hibernate.initialize() seems to only work with relations.
Is there an equivalent for 'plain' attributes?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 6:11 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
Not sure it's the best solution, but I have a similar situation and have a class that extends it, e.g. "FullModule extends Module" and then have a different mapping for that without the lazy loading with a new DAO method. In fact, in my scenario the parent does not even have the mappings and my child class adds new mappings (I have one that brings back minimal stuff for listing and a full detail one since I am dealing with longblobs).

This may not be best practice though and I am still relatively new to hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 6:16 am 
Newbie

Joined: Tue Aug 09, 2005 7:02 pm
Posts: 7
Well that is probably a way to go but I am also not sure if this is the best way. I was assuming that Hibernate.initialize() would load these properties.

Having an extra class with other mappings seems does not help me.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 6:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
from Module fetch all properties


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 6:37 am 
Newbie

Joined: Tue Aug 09, 2005 7:02 pm
Posts: 7
Ok, that does the trick. Although now I have to create a HQL and cannot just use load() or get().

Also, when I update the object now and the lazy fields ARE initialized they are not updated to the DB, although I changed a value.

I thought, if I have lazy fields which are initialized and they are updated, then they should also be written to the DB, no??

Thanks.


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