• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate generated query for a inheritance mapping

 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any thoughts on this
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic