-->
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.  [ 4 posts ] 
Author Message
 Post subject: Complex One-to-many relation & Discriminator on many fie
PostPosted: Wed May 17, 2006 7:39 am 
Newbie

Joined: Tue May 16, 2006 3:41 am
Posts: 5
Hibernate version: 3.1

Name and version of the database you are using: Oracle

-------------------------------------------------------------------------
Hi everybody,

I'm actually working on an O/R mapping between an existing application and an existing database. And I meet some problems to map it correctly :

1/ I've got a first class called Risque, abstract, extended by two classes "RisqueA" and "RisqueB" and my inheritance strategy is "one table per concrete class" (so 2 tables here). the problem is those tables contains a same field which is a foreign key pointing on a table called Assurance (and which maps the class Assurance). My question is, How can I map the object Assurance which has an attribute with type "Risque" ?

2/ This time, I'm on a "one table per hierarchy"-strategy. I have to use a discriminator to identify which object has to be instanciated. However, one of my conditions has to refer to 3 differents fields on the datatable. Default discriminators allow to use only one field. But i read in the Hibernate documentation that we can use an attribute of discriminator called "formula"...
So, My questions are :
Can this attribute solve my problem ?
Or :
How do we use it ? And when ?
Do we use it in addition of the discriminator column ?
Or can we use it to replace the column"s attribute ?


Thanks in advance for all those who could help me solving those problem.

_________________
See you, space cowboy...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 11:41 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
1) The association from Assurance to Risque should refer to Risque, not the subclasses. Hibernate will sort out the rest. There is nothing special that you have to to, it's just like having an association to a class with no subclasses.

2) Yes, it looks like formula is what you need. Put your SQL (not HQL) code in the formula. Subqueries are allowed. Case is more usual, though:
Code:
<discriminator type="int">
  <formula>
    case when (col1 > (col4 * 7) and col2 = 'test')) then 1
         when (col2 <> 'test') then 2
    else (select t.disc from table t where t.id = tableid)
    end
  </formula>
</discriminator>
Columns without prefixes used in the formula (tableid, in the example above) are from the main table: if you have a <join> you cannot use columns from it, and you also can't use columns from joined-subclass tables.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 2:42 am 
Newbie

Joined: Tue May 16, 2006 3:41 am
Posts: 5
Thanks for your answer and sorry to do not have answered before... but i was working on another project... I gonna tried it this week but it seems the second problem is going to be solved :)

For the first one, I'm going to try it too :)

Thanks another time for your answer :)

_________________
See you, space cowboy...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 10:13 am 
Newbie

Joined: Tue May 16, 2006 3:41 am
Posts: 5
Hi,
Thanks for your help, my inheritance is ok... excuse me for the time you wait before receiving your credit ;)

_________________
See you, space cowboy...


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