-->
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.  [ 6 posts ] 
Author Message
 Post subject: mix subclass and joined-subclass
PostPosted: Thu Aug 26, 2004 3:33 am 
Newbie

Joined: Thu Aug 26, 2004 3:05 am
Posts: 4
Location: Austria, Linz
hi,
is there any way to mix <subclass> and <joined-subclass> in one mapping file?

i have the following class hierachy:

class item{
...
}

class asset extends item{
...
}


class mobile extends asset{
...
}

now, objects of class item and class asset should be stored in one table. therefore i used the subclass tag.

==== item.hbm.xml=======
...
<class name="Item" table="item" discriminator-value="I">

<id name="id" type="integer" unsaved-value="-1">
<column name="id" sql-type="number" not-null="true" />
<generator class="sequence">
<param name="sequence">item_seq</param>
</generator>
</id>

<discriminator column="classtype" />

<subclass name="Asset" discriminator-value="A">
<property name="sapOrderNumber">
<column name="ordernumber" not-null="false" />
</property>
</subclass-->
...
==============

so this works fine but now i want to store objects of class mobile in another table. this table has a one-to-one assotiation to the item-table. so i think i have to use a joined-subclass.

i tried to put this mapping also in the mapping above but it's not possible to mix subclass and joined-subclass in one mapping.
...
<joined-subclass name="Mobile" table="mobile">
<key column="item_id" />
<property name="serialnumber" column="imei"/>
</joined-subclass>
...

is there another way to manage this problem?

thx for help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 5:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Its not possible in Hibernate 2.1. It is possible in 3.0. See my recent blog entry.


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

Joined: Fri Dec 17, 2004 8:46 am
Posts: 5
Location: Campo Grande / MS
gavin wrote:
Its not possible in Hibernate 2.1. It is possible in 3.0. See my recent blog entry.

and:

public abstract class Documento{
...
}

public class Proposicao extends Documento{
...
}

public class Veto extends Proposicao{
Proposicao proposicaoPai;
}

I am trying to make one automatic relationship (Proposicao and Veto).
The error message is when i try this:
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;
   }


The error:
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]

(my english is bad.. :))

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


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

Joined: Fri Dec 17, 2004 8:46 am
Posts: 5
Location: Campo Grande / MS
I forgot post .hbm.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class name="sl.model.Documento" table="TB_DOCUMENTO" discriminator-value="D">
      <id name="idDocumento" column="PK_DOCUMENTO">
         <generator class="increment" />
      </id>

      <discriminator column="DO_TIPO" />
      
      <subclass name="sl.model.Proposicao" discriminator-value="P">
         <many-to-one name="regimeTramite" column="FK_REG_TRAMITE" />
         <property name="dataAlteracao" column="DO_DATA_ALTERACAO" />
         
      </subclass>
      
      <subclass name="sl.model.Veto" discriminator-value="V">
         <many-to-one name="proposicaoPai" column="FK_PAI" />
      </subclass>
      
   </class>
</hibernate-mapping>


Thanks...

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


Top
 Profile  
 
 Post subject: hibernate query
PostPosted: Tue Jan 25, 2005 2:31 pm 
Newbie

Joined: Thu Aug 26, 2004 3:05 am
Posts: 4
Location: Austria, Linz
i´m not shure which result you expect but if you would load a collection of Proposicao objects I think you have a mistake in your query.

...
session.find("from Proposicao obj order by obj.tipoProposicao");
...


Top
 Profile  
 
 Post subject: Re: hibernate query
PostPosted: Wed Jan 26, 2005 7:07 am 
Newbie

Joined: Fri Dec 17, 2004 8:46 am
Posts: 5
Location: Campo Grande / MS
Problem solved, I changed the mapping

Code:
<subclass name="sl.model.Proposicao" discriminator-value="P">
   <many-to-one name="regimeTramite" column="FK_REG_TRAMITE" />
   <many-to-one name="tipoProposicao" column="FK_TIPO_PROP" />
   <subclass name="sl.model.Veto" discriminator-value="V">
      <many-to-one name="fkPai" column="FK_PAI" />
   </subclass>
</subclass>


Thanks ... :)

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


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