-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to obtain discriminator value in base-class
PostPosted: Thu May 20, 2004 3:06 pm 
Newbie

Joined: Wed Mar 24, 2004 11:13 am
Posts: 15
Location: Norcross, GA
I have been using Hibernate 2.1.2 and MSSQLServer using Type 4 JDBC driver along with Spring and Weblogic.

I have been able to use table-per-class-hierarchy mapping strategy to persist and retrieve data.

Now I have run into a situation wherein I have to know the discriminator value given the primary key. Based on that, I will have to retrieve the corresponding subclass instance.

For eg. using the example in Ch.16,

I want to retrieve the payment type given the "id".

I tried the following HQL query.
"from Payment as payment where payment.id=:id"

With this method.
public String getPaymentType(int id) throws SomeException{
....................
}

A "null" is returned no matter what. I can retrieve other columns without any problem.

Is there a workaround?
Thanks
Madhu


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 20, 2004 3:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Do you have the discriminator mapped as a property on the base class?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 20, 2004 3:26 pm 
Newbie

Joined: Wed Mar 24, 2004 11:13 am
Posts: 15
Location: Norcross, GA
In the base class, its not declared as a property.

But as a discriminator, yes.

<discriminator
column="PAYMENT_TYPE"
type="java.lang.String"
/>

Madhu


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 21, 2004 10:45 am 
Newbie

Joined: Wed Mar 24, 2004 11:13 am
Posts: 15
Location: Norcross, GA
Good Morning

I have tried using named hql queries, named sql queries, plain sql queries in conjunction with Hibernate to resolve this problem. My problem still remains unsolved.

Can anyone please tell me if this is possible or not? Hasnt anyone else been in this situatino before? Thats kind of hard to believe.

If I know that its not possible using Hibernate, I can look into alternate options for this single case.

Thanks
Madhu

_________________
Madhu


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 21, 2004 11:18 am 
Newbie

Joined: Wed Mar 24, 2004 11:13 am
Posts: 15
Location: Norcross, GA
Got the fix hiding deep inside an earlier post. Maybe I didnt dig deep enough.
(;-)


In addition to declaring the discriminator as mentioned above,

map the same <property> with insert="false" update="false".

That way, the base class can access the value. It also prohibits the cbase class from changing the discriminator value.

Hopefully others will find this helpful.

Thanks
Madhu

_________________
Madhu


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