-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem on EAGER and @ManyToOne
PostPosted: Fri Apr 02, 2010 4:45 am 
Beginner
Beginner

Joined: Wed May 25, 2005 8:25 am
Posts: 30
Hello everybody,

I'm trying to make a select using a EAGER fetch to select automatically an association.

Unfortunatly, I can't make the EAGER work, the association is getting fetched element by element.



I'm using spring 3.0.1 and hibernate 3.5.0 Final (I've just migrate from 3.3.2)

I'm trying to execute that select :

Code:
select distinct (wec) from WatchEventCriteria wec where wec.id.watchId = :watchId


I'm making a maxResult(100) and execute the query.

Here are the generated logs (I've troncated the last lines, there is 102 query approximately)

Code:
Hibernate: select * from ( select distinct watchevent0_.CRT_CKA_ID as CRT1_0_, watchevent0_.CRT_ID as CRT2_0_, watchevent0_.EVENT_ID as EVENT3_0_, watchevent0_.WATCH_ID as WATCH4_0_, watchevent0_.CREATED_BY as CREATED5_0_, watchevent0_.DATE_CREATED as DATE6_0_, watchevent0_.DATE_MODIFIED as DATE7_0_, watchevent0_.MODIFIED_BY as MODIFIED8_0_, watchevent0_.ORDER_BY as ORDER9_0_ from CHAIREMRC.MRC_WATCH_EVENT_CRITERIA watchevent0_, CHAIREMRC.MRC_EVENTS event1_ where
watchevent0_.EVENT_ID=event1_.id and watchevent0_.WATCH_ID=? ) where rownum <= ?

Hibernate: select criteria0_.CKA_ID as CKA1_10_0_, criteria0_.id as id10_0_, criteria0_.CREATED_BY as CREATED3_10_0_, criteria0_.DATE_CREATED as DATE4_10_0_, criteria0_.DATE_MODIFIED as DATE5_10_0_, criteria0_.MODIFIED_BY as MODIFIED6_10_0_ from CHAIREMRC.MRC_CRITERIA criteria0_ where criteria0_.CKA_ID=? and criteria0_.id=?

Hibernate: select event0_.id as id3_4_, event0_.ACTOR_NAME as ACTOR2_3_4_, event0_.C1_REFERENCE as C3_3_4_, event0_.C2_REFERENCE as C4_3_4_, event0_.C3_REFERENCE as C5_3_4_, event0_.COMPANY_NAME as COMPANY6_3_4_, event0_.CREATED_BY as CREATED7_3_4_, event0_.DATE_CREATED as DATE8_3_4_, event0_.DATE_MODIFIED as DATE9_3_4_, event0_.DATE_VALIDATED1 as DATE10_3_4_, event0_.DATE_VALIDATED2 as DATE11_3_4_, event0_.DOC_DIRECTORY as DOC12_3_4_, event0_.ID_MONTH as ID13_3_4_, event0_.LIBEL_COUNTRY_INIT as LIBEL14_3_4_, event0_.LIBEL_SECTEUR_INIT as LIBEL15_3_4_, event0_.MODIFIED_BY as MODIFIED16_3_4_, event0_.KCONTINENT_ID as KCONTINENT24_3_4_, event0_.KCOUNTRY_ID as KCOUNTRY25_3_4_, event0_.KORIGIN_ID as KORIGIN26_3_4_, event0_.KSECTEUR_ID as KSECTEUR27_3_4_, event0_.note as note3_4_, event0_.place as place3_4_, event0_.PUBLICATION_DATE as PUBLICA19_3_4_, event0_.REF_NOTE as REF20_3_4_, event0_.REF_RAPPORT_MENS as REF21_3_4_, event0_.VALIDOR1_BY as VALIDOR22_3_4_, event0_.VALIDOR2_BY as VALIDOR23_3_4_, kindofcont1_.id as id12_0_, kindofcont1_.CREATED_BY as CREATED2_12_0_, kindofcont1_.DATE_CREATED as DATE3_12_0_, kindofcont1_.DATE_MODIFIED as DATE4_12_0_, kindofcont1_.MODIFIED_BY as MODIFIED5_12_0_, kindofcoun2_.id as id7_1_, kindofcoun2_.CREATED_BY as CREATED2_7_1_, kindofcoun2_.DATE_CREATED as DATE3_7_1_, kindofcoun2_.DATE_MODIFIED as DATE4_7_1_, kindofcoun2_.MODIFIED_BY as MODIFIED5_7_1_, kindofcoun2_.KOC_CONTINENT_ID as KOC6_7_1_, mrcwatchev3_.EVENT_ID as EVENT3_3_6_, mrcwatchev3_.CRT_CKA_ID as CRT1_6_, mrcwatchev3_.CRT_ID as CRT2_6_, mrcwatchev3_.EVENT_ID as EVENT3_6_, mrcwatchev3_.WATCH_ID as WATCH4_6_, mrcwatchev3_.CRT_CKA_ID as CRT1_0_2_, mrcwatchev3_.CRT_ID as CRT2_0_2_, mrcwatchev3_.EVENT_ID as EVENT3_0_2_, mrcwatchev3_.WATCH_ID as WATCH4_0_2_, mrcwatchev3_.CREATED_BY as CREATED5_0_2_, mrcwatchev3_.DATE_CREATED as DATE6_0_2_, mrcwatchev3_.DATE_MODIFIED as DATE7_0_2_, mrcwatchev3_.MODIFIED_BY as MODIFIED8_0_2_, mrcwatchev3_.ORDER_BY as ORDER9_0_2_, criteria4_.CKA_ID as CKA1_10_3_, criteria4_.id as id10_3_, criteria4_.CREATED_BY as CREATED3_10_3_, criteria4_.DATE_CREATED as DATE4_10_3_, criteria4_.DATE_MODIFIED as DATE5_10_3_, criteria4_.MODIFIED_BY as MODIFIED6_10_3_ from CHAIREMRC.MRC_EVENTS event0_, CHAIREMRC.MRC_KIND_OF_CONTINENT kindofcont1_, CHAIREMRC.MRC_KIND_OF_COUNTRY kindofcoun2_, CHAIREMRC.MRC_WATCH_EVENT_CRITERIA mrcwatchev3_, CHAIREMRC.MRC_CRITERIA criteria4_ where event0_.KCONTINENT_ID=kindofcont1_.id(+) and event0_.KCOUNTRY_ID=kindofcoun2_.id(+) and event0_.id=mrcwatchev3_.EVENT_ID(+) and mrcwatchev3_.CRT_CKA_ID=criteria4_.CKA_ID(+) and mrcwatchev3_.CRT_ID=criteria4_.id(+) and event0_.id=?

...


Here is the mapping

Table WatchEventCriteria :

Code:
@Entity
@Table(name="MRC_WATCH_EVENT_CRITERIA")
public class WatchEventCriteria implements Serializable {

...

@ManyToOne(fetch=FetchType.EAGER)
   @JoinColumns({
      @JoinColumn(name="CRT_ID", referencedColumnName="ID",updatable = false, insertable = false),
      @JoinColumn(name="CRT_CKA_ID", referencedColumnName="CKA_ID",updatable = false, insertable = false),
      })
   private Criteria mrcCriteria;

   //bi-directional many-to-one association to Event
   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name="EVENT_ID",updatable = false, insertable = false)
   private Event mrcEvent;


...



Table Event:

Code:
@Entity
@Table(name="MRC_EVENTS")
public class Event implements Serializable {

...
//bi-directional many-to-one association to WatchEventCriteria
   @OneToMany(mappedBy="mrcEvent",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
   @Cascade( { org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
   private List<WatchEventCriteria> mrcWatchEventCriterias;

...
}


I also try : @Fetch(FetchType.JOIN) without any success.


Thanks for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.