-->
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.  [ 1 post ] 
Author Message
 Post subject: Accessing to association defined on subclass
PostPosted: Tue Sep 04, 2007 9:55 am 
Newbie

Joined: Mon Sep 03, 2007 2:11 pm
Posts: 2
Location: Japan
Hello Hibernate developers and community people,

I am aware that HQL (in Hibernate 3.2) allows accessing to an association defined on a subclass through its superclass (I will describe in detail below), and I am posting here because I would like to make sure that this was a designed behavior but not incidental. I would appreciate if I could get information from someone who knew the design intention or who could point out a documentation that I had been missing.

Here is a minimal example.

I have three classes. 'AbstractA' and its subclass 'ConcreteA' are mapped to a table by STI strategy. ConcreteA has a many-to-one association to the third class, 'B'. Note this association is defined on ConcreteA so AbstractA knows nothing about it.

Code:
<class name="AbstractA" table="A">
  <id name="id"/>
  <discriminator column="DISC" type="string"/>
</class>

<subclass name="ConcreteA" extends="AbstractA">
  <many-to-one name="b" class="B"/>
</subclass>

<class name="B">
  <id name="id"/>
</class>


Upon this mapping and the class definition behind, an HQL below works well:

Code:
select a, b from AbstractA a inner join a.b b


The point is that Hibernate interprets association 'a.b' in the join clause according to the mapping defined for ConcreteA (as I wished) although 'a' is merely an alias of AbstractA. In an object-oriented sense, AbstractA should know nothing about ConcreteA or association 'b'.

As to my code reading of Hibernate, I believe this behavior is intended. I found an explicit code that was searching for the specified property name in subclass's property name closure, not only superclass's, when building SQL AST from HQL AST.

Because I need to rely on this behavior for some reasons, I would like to make sure that my code reading is correct and I could use this safely as Hibernate's designed feature. So far, I have failed to find any documentation about this in the HQL reference. I would appreciate it if someone here could give me a light on it.

Thank you in advance,
Tomoto


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.