-->
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.  [ 3 posts ] 
Author Message
 Post subject: same field for many-to-one and discriminator, is possible?
PostPosted: Thu Oct 21, 2004 4:14 pm 
Newbie

Joined: Fri Oct 15, 2004 4:56 pm
Posts: 1
Hi, I've been trying to map a table that has a field that I want to use both as discriminator and as a many-to-one relation.
I tried all kind of combinations but hibernate doesn't seem to like it.
The Table "Valor" is mapped using the table-per-class-hierarchy mapping strategy, and I also have another table "Tipo_Valor" (mapped to class "TipoValor") that enumerates the different types of "Valor" that exist. In "Valor" there's a field called "tipo_valor" that is the foreign key to the table "Tipo_Valor".
Is there any reason why I can't use the field "tipo_valor" as a many-to-one relation to "TipoValor" and as a discriminator for subclasses of "Valor" as well??
Here is my mapping:

<hibernate-mapping>
<class
name="com.zetti.ftweb.valores.modelo.Valor"
table="VALOR"
>

<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="sequence">
</generator>
</id>

<discriminator
column="tipoValor"
/>

<many-to-one
name="tipoValor"
class="com.zetti.ftweb.valores.modelo.TipoValor"
cascade="none"
outer-join="auto"
column="tipo_valor"
/>

<property
name="codificacion"
type="java.lang.String"
column="codificacion"
/>

<subclass
name="com.zetti.ftweb.valores.modelo.Billete"
discriminator-value="3"
>
....
</subclass>

<subclass
name="com.zetti.ftweb.valores.modelo.NotaCredito"
discriminator-value="8"
>
....
</subclass>
....
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 07, 2004 8:13 pm 
Newbie

Joined: Mon Sep 27, 2004 11:39 pm
Posts: 4
hi carinatrujillo,

did you solve this problem? is it easiest just to leave out the MANY-TO-ONE mapping for the descriminator column?


Top
 Profile  
 
 Post subject: Re: same field for many-to-one and discriminator, is possibl
PostPosted: Mon Nov 08, 2004 7:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
carinatrujillo wrote:
Is there any reason why I can't use the field "tipo_valor" as a many-to-one relation to "TipoValor" and as a discriminator for subclasses of "Valor" as well??

You can't because in Java you can't change the instance class by changing a many-to-one assoc elsewhere.
What you can do is mapping the many-to-one with insert=false update=false

_________________
Emmanuel


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