-->
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.  [ 4 posts ] 
Author Message
 Post subject: Initialising UserType but need attribute from owner
PostPosted: Wed Feb 01, 2006 7:24 am 
Newbie

Joined: Wed Feb 01, 2006 6:07 am
Posts: 2
Hi All,

I have a mapping file, an extract of which is below:

Code:
<hibernate-mapping>
   <class name="business.requisition.Requisition"
         optimistic-lock="version"
         table="EPT602">
      <id type="long" name="id">
         <generator class="sequence">
            <param name="sequence">requisitionSequence</param>
         </generator>
      </id>
      <property name="date" not-null="true"/>
      <property name="requisitionedPosition"
            not-null="true"
            type="business.structure.PeopleSoftPosition">
         <column name="requisitioned_position"/>
      </property>
      <many-to-one name="brand" column="brand" foreign-key="EPR602I"/>
   </class>
</hibernate-mapping>


I have cut out a lot of detail but the remaining elements appear in their orginal order.

The requisitionedPosition property maps to an instance PeopleSoftPosition which implements net.sf.hibernate.UserType so that it can call a network service to initialise itself through the nullSafeGet method:

Code:
public Object nullSafeGet(ResultSet rs, String[] names, Object owner){ ... }


My problem is that some requirements have changed, and in order to do the look up in PeopleSoftPosition, I now need to know the brand property from the Requisition object.

Within nullSafeGet I have determined that the "owner" of a PeopleSoftPosition is a Requisition object - but apart from id, every field on it is null!

I even tried to reload the Requisition object through a org.springframework.orm.hibernate.support.HibernateDaoSupport class with the following call:
Code:
   Requisition req = (Requisition) getHibernateTemplate().load(Requisition.class, id);

but I get back the same result, an object with all other fields apart from id being null.

This is so strange because I use the HibernateDaoSupport ok in other parts of the app. I cannot work out what is going wrong here - am I trying to use a Requisition owner that hasn't yet been initialised? Or can I fix this by changing the order of elements in the mapping?

Any help would be most appreciated!

Rob
:)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 9:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
At the time your nullSafeGet is called, Hibernate is still processing the result set. These values are not yet injected onto the entity (your owner) as that happens after all the values have been pulled from the result set

You might want to consider performing this through event listener hooks instead.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 04, 2006 8:53 pm 
Newbie

Joined: Wed Feb 01, 2006 6:07 am
Posts: 2
Thank you very much for your reply Steve,

To get around this, I had the owner class (Requisition) implement net.sf.hibernate.Lifecycle and arranged so that the 'child' objects are loaded in the 'onLoad' method. We aren't using Hibernate 3, so we can't use the new event handling system, but net.sf.hibernate.Lifecycle seems to work fine.

Thank you again for your response!

Rob
:)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 04, 2006 10:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
np. but keep in mind that Lifecycle is deprecated as of Hibernate3...


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