aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate generated query for a inheritance mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate generated query for a inheritance mapping" Watch "Hibernate generated query for a inheritance mapping" New topic
Author

Hibernate generated query for a inheritance mapping

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

Hi All,

I have a inheritance mapping between Product and Electronics objects. I have this defined as
single table for subclass model
and using one mapping file for both product and electronics using joined-subclass tag.



After that, I have successfully inserted few records into both the tables, by creating Electronics objects and persisting them.

Now I see two different queries generated by Hibernate, when I try to query Products and Electronics seperately.

If I say

generated query is


from this, I can understand that InnerJoin is used to retrieve Product Name, Product Desc and Product Price, as Electronics extends Product

But, If I say

generated query is


From the above query, I did not understand why do we need to get Category, as Category is an attribute of Electronics and Product does not have any information about its subclass. Also I did not understand the usage of Case here and why do we need to do a left outer join of electronics.

Can't simply Hibernate query against Product alone, instead of complicating with the usage of joins and unnecessary tables. Please advice, if I need to change anything here.


Regards
KumarRaja

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

Any thoughts on this
Justin Chi
Greenhorn

Joined: Sep 09, 2009
Posts: 25
If Hibernate does not left join Electronics, what will happen if you do a session.delete(product) ?

This is how Hibernate works, please note that lazy loading does not work here.

As Electronics object is selected, all it's properties will be in select clause including the ones inherited from its parent and its own attributes like category.

Use plain SQL instead of HQL if you want a clean Product.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate generated query for a inheritance mapping