-->
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: EAGER fetch with FetchMode.JOIN has no effect
PostPosted: Wed Mar 05, 2008 3:30 am 
Newbie

Joined: Tue May 22, 2007 10:52 am
Posts: 13
Hi,

I am setting Eager fetching for OneToOne and ManyToOne relationships, and even though I specify @Fetch(FetchMode.JOIN), it does not work - I mean that even though it is fetching eagerly(at the time of HQL execution) it does not use JOIN, but is still performing additional selects(n+1 selects).

Please help!

To be more concrete the "main" entity is RfqRequest and it links to CoreCurrency (many-to-one) and RfqRequestOciParam(one-to-one).

The HQL is very simple:
Code:
entityManager.createQuery("from RfqRequest req").getResultList()


And it generates many sqls like this:
Code:
18:20:52,715 INFO  [STDOUT] Hibernate: /* from RfqRequest req  */ select ...{removed the selected columns}...  from dbo.RFQ_Request rfqrequest0_
18:20:52,871 INFO  [STDOUT] Hibernate: /* load com.ibx.ibxrequest.model.CoreCurrency */ select  ...{removed the selected columns}... from dbo.CORE_Currency corecurren0_ where corecurren0_.CurrencyId=?
18:20:52,871 INFO  [STDOUT] Hibernate: /* load com.ibx.ibxrequest.model.RfqRequestOciParam */ select  ...{removed the selected columns}... from dbo.RFQ_RequestOCIParam rfqrequest0_ where rfqrequest0_.RequestId=?


Here is an excerpt from RfqRequest entity with the 2 links:
Code:

@Entity
@Table(name = "RFQ_Request", uniqueConstraints = {})
public class RfqRequest implements java.io.Serializable {
....
   @ManyToOne(cascade = {}, fetch = FetchType.EAGER)
   @Fetch(FetchMode.JOIN)
   @LazyToOne(LazyToOneOption.FALSE)
   @JoinColumn(name = "CurrencyId", unique = false, nullable = true, insertable = true, updatable = true)   
   public CoreCurrency getRfqCurIso() {
      return this.rfqCurIso;
   }

   @PrimaryKeyJoinColumn
   @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
   @Fetch(FetchMode.JOIN)
   @LazyToOne(LazyToOneOption.FALSE)
   public RfqRequestOciParam getOciParams() {
      return ociParams;
   }

....
}


Here is an excerpt from the referred CoreCurrency entity:
Code:
@Entity
@Table(name = "CORE_Currency", uniqueConstraints = { @UniqueConstraint(columnNames = { "CurISO" }) })
public class CoreCurrency implements java.io.Serializable {
.....   
        @Id
   @GeneratedValue
   @Column(name = "CurrencyId", unique = true, nullable = false, insertable = true, updatable = true)
   public Integer getCurrencyId() {
      return this.currencyId;
   }
....
}


And the RfqRequestOciParam entity
Code:
@Entity
@Table(name = "RFQ_RequestOCIParam",  uniqueConstraints = {})
public class RfqRequestOciParam implements java.io.Serializable {
...
   @Id
   @GeneratedValue(generator = "myForeignGenerator")
   @GenericGenerator(   name = "myForeignGenerator", strategy = "foreign",
                  parameters = @Parameter(name = "property", value = "rfqRequest") )   
   @Column(name = "RequestId", unique = true, nullable = false, insertable = true, updatable = true)
   public Integer getRequestId() {
      return this.requestId;
   }
   @OneToOne(cascade = {}, fetch = FetchType.LAZY, mappedBy="ociParams" )
   public RfqRequest getRfqRequest() {
      return this.rfqRequest;
   }
...
}


Hibernate version:
[Version] Hibernate Annotations 3.3.0.GA
[Environment] Hibernate 3.2.4.sp1
[Version] Hibernate EntityManager 3.3.1.GA
[Version] Hibernate Validator 3.0.0.GA
[Version] Hibernate Search 3.0.0.GA

Name and version of the database you are using:
[SettingsFactory] RDBMS: Microsoft SQL Server, version: 08.00.2039
[SettingsFactory] JDBC driver: jTDS Type 4 JDBC Driver for MS SQL Server and Sybase, version: 1.2
[Dialect] Using dialect: org.hibernate.dialect.SQLServerDialect


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.