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