The moose likes Object Relational Mapping and the fly likes Hibernate - Slow Query on Entity Superclass 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 - Slow Query on Entity Superclass" Watch "Hibernate - Slow Query on Entity Superclass" New topic

Hibernate - Slow Query on Entity Superclass

Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 160

Hi Guys

I have a quick question regarding Hibernate entity mappings.

I have a Java project in NetBeans, using Hibernate as persistence manager, with all the default settings. I have two entity classes in my application; each of them extends the same superclass.

When executing a select query on the superclass, it takes around two and a half minutes. When executing individual queries on each of the two tables, each of them takes less than a second. How can I speed up the query on the super class? We want to be able to run a report over both tables with a single query, but the user should be able to edit each table without affecting the other - therefore we created two tables with a common super class.

I'm no Hibernate expert, so please let me know if you need any additional information.

Thanks and Regards,
Riaan Nel

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

What SQL is Hibernate generating?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 160

Paul Sturrock wrote:What SQL is Hibernate generating?

Hi Paul, thanks for your response. Hibernate is generating a union between the tables for the two subclasses. I'm not sure whether it will be possible to speed it up.

I agree. Here's the link:
subject: Hibernate - Slow Query on Entity Superclass
jQuery in Action, 3rd edition