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.  [ 2 posts ] 
Author Message
 Post subject: One-to-One with Inheritance
PostPosted: Fri Apr 09, 2010 5:02 am 
Beginner
Beginner

Joined: Thu Jul 31, 2008 8:28 pm
Posts: 24
Hi,
I'm developing an J2EE 6 application using JPA and Hibernate as provider.
I have entity called Survey which have property called payload of type SurveyPayload which map as OneToOne, that is for each survey I have exactly one payload and vice-versa. The payload property is required (not optional).

The SurveyPayload class is super class for two other classes (entities) which are called LongSurveyPayload and ShortSurveyPayload each contain different properties.

I've chose this design to be able to use surveys generally without caring which actual payload is attached to them.

The problem I'm facing is the usual N+1 select problem.
When I select all the surveys and I know in advance that I'm going to need the payload of each one I'm selecting them with the following query:
Code:
select s
from Survey s
join fetch s.surveyPayload


The output I see generated by hibernate is
Code:
INFO: Hibernate: select survey0_.id as id20_0_, ... surveypayl1_.clazz_ as clazz_1_ from Survey survey0_
inner join (
  select id, .. 1 as clazz_ from ShortSurveyPayload
  union
  select id, .. 2 as clazz_ from LongSurveyPayload
) surveypayl1_ on survey0_.surveyPayload_id=surveypayl1_.id

I've trim the sql to make it clearer

which really select all the surveys and join on a union of both payload types. But then I start to see a line for each survey to select its payload.


It is literally taking for ever to complete this select and there is only around 200 surveys and payloads.
Any ideas how to fix this problem?

Thank you,
Ido.


Top
 Profile  
 
 Post subject: Re: One-to-One with Inheritance
PostPosted: Sun Apr 11, 2010 3:41 am 
Beginner
Beginner

Joined: Thu Jul 31, 2008 8:28 pm
Posts: 24
Hi,
Any ideas?

Thank you,
Ido.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.