Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Does parent property for component inside component work?
PostPosted: Wed Mar 14, 2012 1:43 pm 
Regular
Regular

Joined: Thu Nov 30, 2006 10:48 am
Posts: 59
I have the following association relationships: LFOTechnician 1:1 LFOJob 1:1 LFOOrder. All are bi-directional; therefore, LFOTechnician has a reference to LFOJob and LFOJob has a reference to its parent, LFOTechnician. Similarly, LFOJob has a reference to LFOOrder and LFOOrder has a reference to its parent, LFOJob. To emphasize: there are 3 objects/classes.

I have a single database table, LFOTechnicianTB, will all of the fields for LFOTechnician, LFOJob, and LFOOrder in it. I want to use Hibernate's Component element to map this. I try to do this where the LFOJob is a Component of LFOTechnciian and ... LFOOrder is a Component within the LFOJob Component (nested). Things are ok except when the Hibernate parent property for LFOOrder (to its parent, LFOJob) is set - Hibernate says it's the wrong type (it sees it not as LFOJob but, instead, as LFOTechnician).

Here's the item that's causing the error:
<component name="lfoOrder" class="com.att.escc.dm.lfo.LFOOrder" unique="true">
<parent name="job"/>

Here's the error;

51882 [main] ERROR org.hibernate.property.BasicPropertyAccessor - IllegalArgumentException in class: com.att.escc.dm.lfo.LFOOrder, setter method of property: job
51882 [main] ERROR org.hibernate.property.BasicPropertyAccessor - expected type: com.att.escc.dm.lfo.LFOJob, actual value: com.att.escc.dm.lfo.LFOTechnician


Mappiing file (without other properties):

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.att.escc.dm.lfo.LFOTechnician" table="LFOTechnicianTB">
   
        <id name="ID" type="int">
            <column name="ID"/>
         <generator class="sequence">
            <param name="sequence">TECHNICIANIDSEQ</param>
         </generator>
        </id>
   <component name="lfoJob" class="com.att.escc.dm.lfo.LFOJob" unique="true">
      <parent name="lfoTechnician"/>
              <component name="lfoOrder" class="com.att.escc.dm.lfo.LFOOrder" unique="true">
         <parent name="job"/>
      </component>         
   </component>
    </class>
</hibernate-mapping>


Domain Model Objects:
Code:
package com.att.escc.dm.lfo;
public class LFOJob
{
   public LFOTechnician getLfoTechnician() { return lfoTechnician; }
   public void setLfoTechnician(LFOTechnician lfoTechnician) { this.lfoTechnician = lfoTechnician; }

   public LFOOrder getLfoOrder() { return lfoOrder; }
   public void setLfoOrder(LFOOrder lfoOrder) { this.lfoOrder = lfoOrder; }
   
   private LFOTechnician lfoTechnician; // parent reference   private LFOOrder lfoOrder; // has-a LFOOrder   
}

public class LFOTechnician
{
   public String getTelephoneNumber() { return telephoneNumber; }
   public void setTelephoneNumber(String telephoneNumber) { this.telephoneNumber = telephoneNumber; }

   public LFOJob getLfoJob() { return lfoJob; }
   public void setLfoJob(LFOJob lfoJob) { this.lfoJob = lfoJob; }
   private LFOJob lfoJob; // has-a LFOJob
}

package com.att.escc.dm.lfo;
public class LFOOrder
{
   public LFOJob getJob() { return job; }
   public void setJob(LFOJob job) { this.job = job; }[/
   private LFOJob job;
}


Hibernate session code (spring's getHibernateSession() is used to manage the hibernate session):

Code:
List<LFOTechnician> technicians = null;
DetachedCriteria criteria = DetachedCriteria.forClass(LFOTechnician.class);
criteria.add(Restrictions.isNotNull("ID"));
technicians = getHibernateTemplate().findByCriteria(criteria);

_________________
metazone


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.