-->
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: Descriminator Against another table?
PostPosted: Tue May 13, 2008 5:39 pm 
Newbie

Joined: Thu Nov 08, 2007 5:02 pm
Posts: 6
I am trying to map a complicated schema which has a table that contains several different subtypes but the descriminator on that table is an id into a second table that names the subtype. This schema was made to be very generic so we can have one instance of the schema for each customer and allow each customer's schema to have different subtypes.

table Foo:{id, foo_type_id, ... }

table Foo_Type {foo_type_id, ....}

I tried maping the Foo subtypes using a @DiscriminatorFormula but hibernate seems to choke when it tries to generate the SQL. Is there a way to discriminate a subtype by referencing a different table?


Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 10:53 am 
Newbie

Joined: Thu Nov 08, 2007 5:02 pm
Posts: 6
I figured it out on my own but I will post the answer here in case anyone else has the same problem.

I wrapped the subselect in the @DiscriminatorFormula annotation with parenthesis.

@Entity
...
@DiscriminatorFormula(
"(select Foo_Type.type from Foo_Type where Foo_Type.foo_type_id = foo_type_id )"
)

by adding the parenthesis, hibernate was able to add the sub select inside the Foo SQL select clause.

select id, foo_type_id, (select Foo_Type.type from Foo_Type where Foo_Type.foo_type_id = foo_type_id ) from ....


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 12:58 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Very clever!

Thanks for posting the solution. So many people forget to.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.