-->
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: EntityManager.find eagerly loading all relationships
PostPosted: Mon Feb 08, 2010 1:48 pm 
Newbie

Joined: Wed Feb 03, 2010 9:17 am
Posts: 5
Hello there! I'm using the Single Table strategy mapping

Code:

@Entity
@Table(name="MEDIA")
@DiscriminatorColumn(name="TYPE")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public abstract class AbstractMedia extends BaseEntity {


@Entity
@DiscriminatorValue("V")
public class VideoElement extends MediaElement<VideoCapability> {



When I load a VideoElement using find, Hibernate respects all the Lazy relationships, but when querying for AbstractMedia, it joins all the tables of super class + subclasses. The query is huge, we have some subclasses that uses polymorphic association, and it joins every single table of every single possible concrete class. I've noticed that only happens with find. If I create a query using hql it does not happen.

Is this the default behavior?

Regards


Top
 Profile  
 
 Post subject: Re: EntityManager.find eagerly loading all relationships
PostPosted: Mon Feb 08, 2010 2:05 pm 
Newbie

Joined: Wed Feb 03, 2010 9:17 am
Posts: 5
Well, digging it, I found that Hibernate does not load the relationships, they are lazy for sure, but, the initial query joins the tables anyway, which is bothering me (and will bother the DBA for sure)

Here's the output of em.find(AbstractMedia.class, id)

Code:
select abstractme0_.ID as ID4_4_, abstractme0_.DELETED as DELETED4_4_, abstractme0_.MEDIA_HASH as MEDIA4_4_4_, abstractme0_.FOLDER_ID as FOLDER7_4_4_, abstractme0_.SHARED as SHARED4_4_, abstractme0_.TITLE as TITLE4_4_, abstractme0_1_.CATEGORY_ID as CATEGORY1_5_4_, abstractme0_.FILE_ID as FILE8_4_4_, abstractme0_.CAPABILITY_ID as CAPABILITY9_4_4_, abstractme0_.TYPE as TYPE4_4_, metadatava1_.MEDIA_ID as MEDIA1_6_, metadatava1_.METADATA_ID as METADATA2_6_, metadatava1_.VALUE as VALUE6_, metadata2_.id as id0_0_, metadata2_.KEY_ATTR as KEY2_0_0_, abstractme3_.ID as ID4_1_, abstractme3_.DELETED as DELETED4_1_, abstractme3_.MEDIA_HASH as MEDIA4_4_1_, abstractme3_.FOLDER_ID as FOLDER7_4_1_, abstractme3_.SHARED as SHARED4_1_, abstractme3_.TITLE as TITLE4_1_, abstractme3_1_.CATEGORY_ID as CATEGORY1_5_1_, abstractme3_.FILE_ID as FILE8_4_1_, abstractme3_.CAPABILITY_ID as CAPABILITY9_4_1_, abstractme3_.TYPE as TYPE4_1_, mediafile4_.ID as ID1_2_, mediafile4_.EXTENSION as EXTENSION1_2_, mediafile4_.FILE_NAME as FILE3_1_2_, mediafile4_.MIME_TYPE as MIME4_1_2_, mediafile4_.SIZE as SIZE1_2_, audiocapab5_.MEDIA_CAPABILITY_ID as MEDIA1_2_3_, audiocapab5_.SAMPLE_RATE as SAMPLE1_7_3_ from MEDIA abstractme0_ left outer join MEDIA_CATEGORY abstractme0_1_ on abstractme0_.ID=abstractme0_1_.MEDIA_ID left outer join METADATA_VALUE metadatava1_ on abstractme0_.ID=metadatava1_.MEDIA_ID left outer join METADATA metadata2_ on metadatava1_.METADATA_ID=metadata2_.id left outer join MEDIA abstractme3_ on abstractme0_.FOLDER_ID=abstractme3_.ID left outer join MEDIA_CATEGORY abstractme3_1_ on abstractme3_.ID=abstractme3_1_.MEDIA_ID left outer join MEDIA_FILE mediafile4_ on abstractme3_.FILE_ID=mediafile4_.ID left outer join AUDIO_CAPABILITY audiocapab5_ on abstractme3_.CAPABILITY_ID=audiocapab5_.MEDIA_CAPABILITY_ID left outer join MEDIA_CAPABILITY audiocapab5_1_ on audiocapab5_.MEDIA_CAPABILITY_ID=audiocapab5_1_.MEDIA_CAPABILITY_ID where abstractme0_.ID=10

Regards


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.