-->
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.  [ 2 posts ] 
Author Message
 Post subject: Class name on joined subclass
PostPosted: Wed Nov 23, 2005 10:24 am 
Newbie

Joined: Tue Aug 30, 2005 3:15 pm
Posts: 3
Ok, I've read the documentation, searched through the Forum, and still can't get no answer, although I think it's something related to a bug.

I have a class PessoaVO which has three joined subclasses - PessoaFisicaVO, PessoaJuridicaVO and InstituicaoEnsinoVO. When querying the main class (PessoaVO), I'd like to know from which joined subclass the object being retrieved belongs to, and since it is a joined subclass, there should be no discriminator, I tried to execute an HQL query:

select obj.class from PessoaVO obj where obj.id=5

When I look on the database, I know the it exists and is an instance of InstituicaoEnsinoVO, but I get the following exception: (translated from portuguese):

The column prefix 'pessoavo0__1_' does not match a table name or alias used on the query. The table is not specified on the FROM clause or has a correlated name that should be used instead.

If I use any other property on the above query (say obj.id) it works flawlessly. I think I'm doing something really stupid here, for I can't see what my mistake is.

Oh, and if I try to execute the query (which for me wouldn't be of much use, but I saw many examples like this on the docs):

select obj.id from PessoaVO obj where obj.id=5 and obj.class = InstituicaoEnsinoVO

I still get the same exception.

Any ideas anyone? What am I doing wrong? Should I use something else other than .class to get the class name?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 10:49 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 4:53 pm
Posts: 41
Location: Netherlands
So you want to know the classname of the joined subclass that is loaded?

Code:
PessoaVO vo = (PessoaVO)session.createQuery("from PessoaVO obj where obj.id=5").uniqueResult();

vo.getClass();
// or
vo.getClass().getName();


These should both return either the Class or classname of InstituicaoEnsinoVO because of polymorphism.
Doing a query in a class that has joined subclasses automaticly returns the correct joined subclass. :)


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