-->
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: What to do if discriminator column is on another table?
PostPosted: Sun May 16, 2004 9:23 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
Quote:
<class name="Document" table="DOCUMENTS">
<id name="id">...</id>
<discriminator column="TYPE" type="string"/>
...
<subclass name="Book" discriminator-value="BOOK"/>
<subclass name="Newspaper" discriminator-value="NEWSPAPER"/>
<subclass name="XML" discriminator-value="XML">
<join table="XML_DOCUMENTS">
....
</join>
</subclass>
</class>



Can I choose the discriminator column from another table, for instance:

]<class name="Document" table="DOCUMENTS">
<id name="id">...</id>
<discriminator type="string"
formula = "(Select a.Name from A a where a.id = id)" />

<subclass name="Book" discriminator-value="BOOK"/>
<subclass name="Newspaper" discriminator-value="NEWSPAPER"/>
<subclass name="XML" discriminator-value="XML">
<join table="XML_DOCUMENTS">
....
</join>
</subclass>


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 16, 2004 11:19 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you have 1 a.Name for 1 yourClass.id isn't it?
why do you need another table?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 16, 2004 11:29 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I do not need another table, if that would be my choice.
there already is another table and I need to persist my object to that table schema done by a "idiot ". I cant change it-)))

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 16, 2004 12:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Formula discriminators are not implemented in Hibernate 2.1. However, it should be an easy job to backport this feature from v22branch, if you really need it. (It is working very nicely in CVS.) I will accept a patch to v21branch if you provide one.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 17, 2004 5:37 am 
Beginner
Beginner

Joined: Tue Nov 25, 2003 11:55 am
Posts: 23
Did somebody patch it? I need to solve the same problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 4:04 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Just in case anyone else was wondering about this today as well. You can indeed put in the select statement to pull the discriminator off another table.

In my case I had a type table that has a CLASS_NAME column in order to create the object by reflection.

I wanted to maintain referential integrity so I wanted to hook the FK to the PK of the type table.

I also wanted to use the CLASS_NAME as the discrim in the 'child' table so using

Code:
        <discriminator
         formula="(select wt.WORKFLOW_EVENT_CLASS from WORKFLOW_TYPE wt where wt.WORKFLOW_TYPE_ID = WORKFLOW_TYPE_ID)"
      type="string"/>


I was able to get exactly what I needed. Learn something new every day with this :D


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.