-->
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: HQL problem with entity-name
PostPosted: Thu Dec 22, 2005 6:05 pm 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
Hibernate version: 3.1

Hello,

I have a single class mapped to two tables, the first one without entity-name attribute (i.e. the default is used), the second one with entity-name.

When I use HQL, I cannot retrieve just instances of the default class (the one mapped without entity-name).

Say the class is named X and mapped to table X, the first mapping without entity-name, the second one with entity-name X2.

Now when I use HQL "from X2", I get instances mapped using entity-name X2.

When I use HQL "from X" I get instances mapped to both tables.

Apparently in HQL the identifiyer (X or X2) is first interpreted as a class, which indeed maps to both entity X and to X2, and only if no class if found ("from X2") the identifier is interpreted as an entity-name.

My question: is there a way to specify that I only want the entity X (so only returing records from table X) and not the class X?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 6:05 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 7:43 am
Posts: 31
Location: León (Spain)
In the <class> tag of the mapping files exists an attribute named "polymorphism". Default value tells Hibernate to return classes and subclasses of the one you query.

http://www.hibernate.org/hib_docs/v3/re ... tion-class

Try specifying: polymorphism="explicit" in the <class> tags.
Bye.

_________________
Please rate...

Expert on Hibernate errors... I've had them all... :P


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 7:14 am 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
Hector_Lopez wrote:
Try specifying: polymorphism="explicit" in the <class> tags.
Bye.


Thanks a lot (credit assigned). This does help in my case.

I can imagine cases however where it doesn't help: in my case I have already an inheritance tree, the subclasses are mapped with <subclass> element which doesn't allow for polymorphism="explicit", so I had to disable implicit polymorphism for the whole class hierarchy.

In my case that does not matter.

Still, is it not strange that this assymetry exists? There seems to be no way in HQL to signify I want the entity X, not the class X. But when I use X2, the entity is taken automatically since no class X2 exists.

I wish there were a way in HQL to tell that I only want the entity X.


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.