-->
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: Subclasses - Newbie question
PostPosted: Fri Jan 14, 2005 10:49 am 
Newbie

Joined: Fri Dec 17, 2004 8:22 am
Posts: 3
Location: Leeds UK
Hibernate version:3 beta 1

All
I currently have the following:

public abstract class Party {
...
}

public abstract class Person extends Party{
...
}

public class Employee extends Person {
...
}

These can all be mapped to a single DB table

The problem I have is when I instantiate either a Person or a employee, when persisting to the DB I alsways get the discriminator of 'E'

I know Im doing something wrong but no amount of cludguing around with the mapping file seems to make any difference.

I could change the classes as a last resort or goto table per concrete class etc but Im using a collegues code at the mo to evaluate hibernate 3 so dont really want to change class code if i can help it!!

Thanks in anticipation..

Mapping File:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.comino.edrms.domain.party">
<class name="Party" table="PARTY">
<id name="id" unsaved-value="null">
<column name="ID" sql-type="BIGINT" not-null="true"/>
<generator class="native"/>
</id>
<discriminator column="POREMP" type="string" length="1"></discriminator>
<property name="emailAddress" column="EMAILADDRESS" type="string" length="50" not-null="true"/>
<property name="address" column="ADDRESS" type="string" length="255" not-null="true"/>
<property name="telNo" column="TELNO" type="string" length="12" not-null="true"/>

<!-- Subclass to represent Person which extend Party-->
<!-- Person Subclass Mapping -->
<subclass name="Person" discriminator-value="P" lazy="true" extends="Party">
<property name="firstName" column="FIRSTNAME" type="string" length="25" not-null="false"/>
<property name="secondName" column="SECONDNAME" type="string" length="25" not-null="false"/>
<property name="title" column="TITLE" type="string" length="12" not-null="false"/>
<property name="surname" column="SURNAME" type="string" length="25" not-null="false"/>
<!-- Nested subclass to represent employees which extend Person-->
<!-- Employee Subclass Mapping -->
<subclass name="Employee" discriminator-value="E" lazy="true" extends="Person" >
<property name="jobTitle" column="JOBTITLE" type="string" length="25" not-null="false"/>
<property name="WhereIwork" column="WHEREIWORK" type="string" length="25" not-null="false"/>
</subclass>
</subclass>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 10:53 am 
Newbie

Joined: Fri Dec 17, 2004 8:22 am
Posts: 3
Location: Leeds UK
Ignoer me ive sorted it!!

I was being dull....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 5:20 pm 
Newbie

Joined: Fri Dec 17, 2004 8:46 am
Posts: 5
Location: Campo Grande / MS
I have the same problem!
You found the solution?

:(

_________________
-------------------


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 5:24 pm 
Newbie

Joined: Fri Dec 17, 2004 8:46 am
Posts: 5
Location: Campo Grande / MS
I have the same problem!
You found the solution?

public abstract class Documento{
...
}

public class Proposicao extends Documento{
...
}

public class Veto extends Proposicao{
...
}


the error message when it executes the following code:

Code:
public List getListOrderTipo() throws HibernateException {
      Session session = sessionFactory.openSession();
      List list =
         session.find(
            "select obj from Proposicao obj order by obj.tipoProposicao");
      session.flush();
      session.close();
      return list;
   }


is:
Code:
net.sf.hibernate.QueryException: could not resolve property: tipoProposicao of: sl.model.Veto [select obj from sl.model.Veto obj order by obj.tipoProposicao]

_________________
-------------------


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 25, 2005 9:20 am 
Newbie

Joined: Fri Dec 17, 2004 8:22 am
Posts: 3
Location: Leeds UK
There was no problem to fix really since I was trying to do the mapping without reviewing the code!

Since I had 2 abstract heirachical classes I didnt really need the switch since everyone in effect was an employee

Not quite the same os yours since you dont have 2 abstracts..
Sorry its not more use..

_________________
Doer of things, maker of pies, smoker of tabs webber of webs:
http://tonyditchfield.co.uk


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.