-->
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: Best Practice for Transient Properties?
PostPosted: Thu Feb 19, 2004 4:49 pm 
Newbie

Joined: Wed Sep 24, 2003 3:30 pm
Posts: 7
Hi,

I'm wondering what's the best way to handle transient properties of persisted object.

I have a persisted class, User, where one attribute is not saved in the database so is not in the hibernate mapping file. User is also in a many-to-one association with Group. If I retrieve the User in one session (say user1) and the Group with its User in another session (user2), all the persisted attributes are the same even though they are not the same object reference (as discussed in sec 2.2 of the ref manual).


I can use onLoad() to initialize the transient property, but if I make change to transient attribute in user1, the change is not reflected user2.

Is there a way that I can map the transient property so that Hiberante handles it across sessions the same way as the persisted properties without actually persisting it the DB?

I was wondering if others have encountered this & how they are addressing it.

Thanks in advance!
Linda :)

Code:
Group.hmb.xml
<hibernate-mapping>
  <class name="eg.Group"
         table="group">
     <id name="id"   
         column="id"
         type ="long"         
         unsaved-value="-1">
         <generator class="native"/>
      </id>
      <property name="name"
            column  ="name"
            type    ="string"
            length  ="25"
            not-null="true"
            unique  ="true"
      />         
   <many-to-one
         name   ="adminUser"
         column="adminUser"
         class   ="eg.User"               
      />

  </class>
</hibernate-mapping>

User.hbm.xml
<hibernate-mapping>
  <class name="eg.User"
         table="user"   >
         
     <id name="id"   
         column="id"
         type ="long"
         unsaved-value="-1">
         
         <generator class="native"/>
      </id>
      <property name     ="name"               
                column   ="name"
                type     ="string"
                length   ="25"
                not-null ="true"
                unique   ="true"
      />         
<!--  this is the transient property
      I'd like to do something like this,
   but a column "tmp" is expected
     <property    name     ="tmp"
         type     ="string"
         insert   ="false"
         update   ="false"
     />   
  -->

  </class>
</hibernate-mapping>



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.