-->
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: Query Performance problem regarding a JPQL Fetch Join
PostPosted: Sun Jan 14, 2007 7:25 pm 
Beginner
Beginner

Joined: Wed Jan 03, 2007 7:47 pm
Posts: 23
Location: Richardson, Texas
Greetings,

I am evaluating Hibernate 3.2 with annotations using an EJB 3 container.

I have defined a named query with fetch join which will select a list of entities based on a non-primary key criteria. The entity has a defined lazy one-to-one relationship (bi-directional) with another entity which should be fetched during the query.

The generated query appears correct joining the 2 tables with the proper criteria; however, there are 4 rows returned and there is another select generated for each row with the criteria of the foreign key of the relationship. I am trying to eliminate the 4 additional selects without any luck.

Here is the code snippet of the query, entity and the relationship.

Code:
@NamedQuery(name="AccessCircuit.findAccessCircuitsByCktId",
   query="SELECT c FROM AccessCircuit c JOIN FETCH c.accessPoint " + "WHERE c.circuitId = :cktId")

@Entity
@Table(name="access_circuit")
public class AccessCircuit implements Serializable {

   // Foreign Key - Access Point (Bi-directional)
   @OneToOne(optional=false, fetch=FetchType.LAZY, cascade=CascadeType.PERSIST)
   @JoinColumn(name="access_point_id")
   private AccessPoint accessPoint;


Here is the log entry of the first query :

/* named HQL query AccessCircuit.findAccessCircuitsByCktId */ select accesscirc0_.access_circuit_id as access1_630_0_, accesspoin1_.access_point_id as access1_631_1_, accesscirc0_.access_point_id as access10_630_0_, accesscirc0_.service_char_id as service9_630_0_, accesscirc0_.object_type as object2_630_0_, accesscirc0_.ckt_id as ckt3_630_0_, accesscirc0_.reference_id_1 as reference4_630_0_, accesscirc0_.reference_id_2 as reference5_630_0_, accesscirc0_.test_flag as test6_630_0_, accesscirc0_.description as descript7_630_0_, accesscirc0_.enterprise_number as enterprise8_630_0_, accesspoin1_.object_type as object2_631_1_, accesspoin1_.state as state631_1_, accesspoin1_.access_type as access4_631_1_, accesspoin1_.speed as speed631_1_, accesspoin1_.clear_channel_flag as clear6_631_1_, accesspoin1_.network_tp_name as network7_631_1_, accesspoin1_.network_resource_name as network8_631_1_, accesspoin1_.ip_address as ip9_631_1_, accesspoin1_.scots_id as scots10_631_1_, accesspoin1_.switch_model_id as switch11_631_1_, accesspoin1_.ds1_line_code as ds12_631_1_, accesspoin1_.channel_ind as channel13_631_1_, accesspoin1_.status_signaling_format as status14_631_1_, accesspoin1_.bi_direction_flag as bi15_631_1_ from access_circuit accesscirc0_, access_point accesspoin1_ where accesscirc0_.access_point_id=accesspoin1_.access_point_id and accesscirc0_.ckt_id=?


Here is the log entry for each subsequent query (repeated 4 times, once for each row) :

/* load src.entity.AccessCircuit */ select accesscirc0_.access_circuit_id as access1_630_0_, accesscirc0_.access_point_id as access10_630_0_, accesscirc0_.service_char_id as service9_630_0_, accesscirc0_.object_type as object2_630_0_, accesscirc0_.ckt_id as ckt3_630_0_, accesscirc0_.reference_id_1 as reference4_630_0_, accesscirc0_.reference_id_2 as reference5_630_0_, accesscirc0_.test_flag as test6_630_0_, accesscirc0_.description as descript7_630_0_, accesscirc0_.enterprise_number as enterprise8_630_0_ from access_circuit accesscirc0_ where accesscirc0_.access_point_id=?


Any help or recommendation is greatly appreciated.

Regards,
Kurt


Top
 Profile  
 
 Post subject: Query Performance problem regarding a JPQL Fetch Join
PostPosted: Mon Jan 15, 2007 11:45 am 
Beginner
Beginner

Joined: Wed Jan 03, 2007 7:47 pm
Posts: 23
Location: Richardson, Texas
I just wanted to give an update on this one. If I rework the query to retrieve the entity on the non-owning side of the relationship using JOIN FETCH on the non-owning, it appears to be working as expected.

Code:
@NamedQuery(name="AccessPoint.findAccessPointsByCktId",
      query="SELECT ap FROM AccessPoint ap JOIN FETCH ap.accessCircuit ac " +
           "JOIN FETCH ac.accessServiceChar sc " +
           "WHERE ac.circuitId = :cktId")


Anybody have any thoughts on this?

Regards,
Kurt


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.