Good day. I am working to introduce Hibernate to an organization that is big into stored procedures and writing out all of the SQL. That said, they are looking at Hibernate very closely and picking out everything. While viewing the SQL trace our DBA has noticed that when doing a select for a one to many relationship, its doing a single select for each and every entity on the many side of the relationship. They don't like this. Performance concerns I suppose. At any rate, is there a setting to get Hibernate to make this request with one query?
My desired outcome would to have the collection lazily loaded, but when it is loaded, that it is done with one select statement. I can not trade the lazy approach for a single select due to performance concerns.
Thanks Hibernate community and developers.
~ Mike
Hibernate version:
Code:
<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.1</version>
<!-- http://www.hibernate.org/ -->
</dependency>
Mapping documents:Code:
<hibernate-mapping default-access="field"
package="com.myco.myapp.internal.model"
schema="database.schema">
<class name="GuidelineSet" table="CodesOwners" lazy="false">
<id name="id" column="OwnerId">
<generator class="identity"/>
</id>
<property name="name" column="OwnerName"/>
<property name="pedsPrefix" column="GuidelinePrefixPeds" lazy="true"/>
<property name="adultPrefix" column="GuidelinePrefixAdult" lazy="true"/>
<!-- guidelines (one-to-many) -->
<set name="guidelines"
table="guidelines"
access="field"
lazy="true"
cascade="all, delete-orphan"
fetch="join">
<key column="OwnerId"/>
<one-to-many class="InternalGuideline" not-found="ignore"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Using Spring ORM - HibernateTemplate.
Name and version of the database you are using:
jTDS Type 4 JDBC Driver for MS SQL Server and Sybase
Microsoft SQL Server