-->
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: Outer Join fetching problem
PostPosted: Fri Nov 04, 2005 6:36 am 
Beginner
Beginner

Joined: Wed Aug 04, 2004 4:33 am
Posts: 45
Location: Switzerland
Hibernate version:2.1.8

Mapping documents:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE hibernate-mapping (View Source for full doctype...)>
- <hibernate-mapping default-cascade="none" default-access="property" auto-import="true">
- <class name="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportData" table="report_data" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" batch-size="1" select-before-update="false" optimistic-lock="version">
- <id name="id" column="id" type="java.lang.String" unsaved-value="null">
- <generator class="com.nexusatwork.framework.hibernate.UUIDIdentifierGenerator">
- <!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-PersistentReportData.xml
containing the additional parameters and place it in your merge dir.

-->
</generator>
</id>
<many-to-one name="reportDefinition" class="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportDefinition" cascade="none" outer-join="false" update="true" insert="true" column="report_def_id" not-null="false" unique="false" />
<property name="storageName" type="java.lang.String" update="true" insert="true" column="storage_name" not-null="false" unique="false" />
- <component name="collectable" class="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentCollectable" update="true" insert="true">
<property name="collectableId" type="java.lang.String" update="true" insert="true" column="collectable_id" not-null="false" unique="false" />
<property name="createdBy" type="java.lang.String" update="true" insert="true" column="created_by" not-null="false" unique="false" />
<property name="createdDate" type="java.util.Date" update="true" insert="true" column="created_date" not-null="false" unique="false" />
<property name="description" type="java.lang.String" update="true" insert="true" column="description" not-null="false" unique="false" />
<property name="modifiedBy" type="java.lang.String" update="true" insert="true" column="modified_by" not-null="false" unique="false" />
<property name="modifiedDate" type="java.util.Date" update="true" insert="true" column="modified_date" not-null="false" unique="false" />
<property name="name" type="java.lang.String" update="true" insert="true" column="name" not-null="false" unique="false" />
<property name="subtitle" type="java.lang.String" update="true" insert="true" column="sub_title" not-null="false" unique="false" />
<property name="title" type="java.lang.String" update="true" insert="true" column="title" not-null="false" unique="false" />
<property name="version" type="java.lang.String" update="true" insert="true" column="version" not-null="false" unique="false" />
</component>
- <!-- To add non XDoclet property mappings, create a file named
hibernate-properties-PersistentReportData.xml
containing the additional properties and place it in your merge dir.

-->
</class>
- <query name="selectReportDataById">
- <![CDATA[ from com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportData repData where repData.id = :id

]]>
</query>

- <query name="selectReportDataByReportDefId">
- <![CDATA[ select repData from com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportData repData, com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportDefinition repDef where repData.reportDefinition = repDef and repDef.id = :id

]]>
</query>
- <query name="selectModifiedDateOfReportDataById">
- <![CDATA[ select repData.collectable.modifiedDate from com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportData repData where repData.id = :id

]]>
</query>
</hibernate-mapping>



===============================================

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE hibernate-mapping (View Source for full doctype...)>
- <hibernate-mapping default-cascade="none" default-access="property" auto-import="true">
- <class name="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportDefinition" table="report_definition" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" batch-size="1" select-before-update="false" optimistic-lock="version">
<cache usage="transactional" />
- <id name="id" column="id" type="java.lang.String" unsaved-value="null">
- <generator class="com.nexusatwork.framework.hibernate.UUIDIdentifierGenerator">
- <!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-PersistentReportDefinition.xml
containing the additional parameters and place it in your merge dir.

-->
</generator>
</id>
- <set name="reportDataList" table="report_data" lazy="true" inverse="true" cascade="none" sort="unsorted" batch-size="1" outer-join="auto">
<key column="report_def_id" />
<one-to-many class="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportData" />
</set>
<many-to-one name="dataFilter" class="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentFilter" cascade="none" outer-join="auto" update="true" insert="true" column="data_filter_id" not-null="false" unique="false" />
<many-to-one name="networkFilter" class="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentFilter" cascade="none" outer-join="auto" update="true" insert="true" column="network_filter_id" not-null="false" unique="false" />
<property name="dataFilterEnabled" type="boolean" update="true" insert="true" column="data_filter_enabled" not-null="false" unique="false" />
<property name="dateFilterEnabled" type="boolean" update="true" insert="true" column="date_filter_enabled" not-null="false" unique="false" />
<property name="groupEnabled" type="boolean" update="true" insert="true" column="group_enabled" not-null="false" unique="false" />
<property name="networkFilterEnabled" type="boolean" update="true" insert="true" column="network_filter_enabled" not-null="false" unique="false" />
- <set name="reportFields" table="report_field" lazy="false" inverse="true" cascade="all-delete-orphan" sort="unsorted" batch-size="1" outer-join="auto">
<key column="report_def_id" />
<one-to-many class="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportField" />
</set>
<property name="sortEnabled" type="boolean" update="true" insert="true" column="sort_enabled" not-null="false" unique="false" />
- <set name="timeSpans" table="time_span" lazy="false" inverse="true" cascade="all-delete-orphan" sort="unsorted" batch-size="1" outer-join="auto">
<key column="report_def_id" />
<one-to-many class="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentTimeSpan" />
</set>
- <set name="reportExports" table="report_export" lazy="false" inverse="true" cascade="all-delete-orphan" sort="unsorted" batch-size="1" outer-join="auto">
<key column="report_def_id" />
<one-to-many class="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportExport" />
</set>
<property name="persistData" type="boolean" update="true" insert="true" column="persist_data" not-null="false" unique="false" />
<property name="view" type="boolean" update="true" insert="true" column="view" not-null="false" unique="false" />
- <component name="collectable" class="com.nexusatwork.nrs.collectable.persistence.mapped.PersistentCollectable" update="true" insert="true">
<property name="collectableId" type="java.lang.String" update="true" insert="true" column="collectable_id" not-null="false" unique="false" />
<property name="createdBy" type="java.lang.String" update="true" insert="true" column="created_by" not-null="false" unique="false" />
<property name="createdDate" type="java.util.Date" update="true" insert="true" column="created_date" not-null="false" unique="false" />
<property name="description" type="java.lang.String" update="true" insert="true" column="description" not-null="false" unique="false" />
<property name="modifiedBy" type="java.lang.String" update="true" insert="true" column="modified_by" not-null="false" unique="false" />
<property name="modifiedDate" type="java.util.Date" update="true" insert="true" column="modified_date" not-null="false" unique="false" />
<property name="name" type="java.lang.String" update="true" insert="true" column="name" not-null="false" unique="false" />
<property name="subtitle" type="java.lang.String" update="true" insert="true" column="sub_title" not-null="false" unique="false" />
<property name="title" type="java.lang.String" update="true" insert="true" column="title" not-null="false" unique="false" />
<property name="version" type="java.lang.String" update="true" insert="true" column="version" not-null="false" unique="false" />
</component>
<property name="accessLevel" type="java.lang.String" update="true" insert="true" column="access_level" not-null="false" unique="false" />
<property name="sourceNode" type="java.lang.String" update="true" insert="true" column="source_node" not-null="false" unique="false" />
<property name="schedulingEnabled" type="boolean" update="true" insert="true" column="scheduling_enabled" not-null="false" unique="false" />
<property name="limit" type="java.lang.Integer" update="true" insert="true" column="record_limit" not-null="false" unique="false" />
<property name="offset" type="java.lang.Integer" update="true" insert="true" column="record_offset" not-null="false" unique="false" />
- <!-- To add non XDoclet property mappings, create a file named
hibernate-properties-PersistentReportDefinition.xml
containing the additional properties and place it in your merge dir.

-->
</class>
- <query name="selectAllReportDefinitions">
- <![CDATA[ from com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportDefinition

]]>
</query>
- <query name="selectReportDefinitionById">
- <![CDATA[ from com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportDefinition repDef where repDef.id = :id

]]>
</query>
- <query name="selectModifiedDateOfReportDefinitionById">
- <![CDATA[ select repDef.collectable.modifiedDate from com.nexusatwork.nrs.collectable.persistence.mapped.PersistentReportDefinition repDef where repDef.id = :id

]]>
</query>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
/**
* Loads the report data.
* @param id id of the report data
* @param session session to execute the query
* @return persitent report data
* @throws NrsRuntimeException when database exception occurs. rollback transaction and close the session yourself!
*/
public PersistentReportData getReportDataById(String id, Session session) {
try {
Query query = session.getNamedQuery(PersistentReportData.QUERY_NAME_SELECT_REPORT_DATA_BY_ID);
query.setString(PersistentReportData.QUERY_PARAM_ID, id);
List<PersistentReportData> persistentReportDataList = (List<PersistentReportData>)query.list();
if (persistentReportDataList.size()>0) {
return persistentReportDataList.get(0);
}
return null;
}
catch (HibernateException he) {
Logger.getLogger(NoStackTraceLogFilter.STACK_TRACE_LOGGER_NAME).log(Level.SEVERE,
StackTraceToStringer.doIt(he));
LOGGER.log(Level.SEVERE, "exception_in_persistence_layer", new String[]{"loading report data", he.getMessage()});
LOGGER.log(Level.SEVERE, "error_loading_report_data_by_id", new String[]{PersistentReportData.QUERY_NAME_SELECT_REPORT_DATA_BY_ID, id});
throw new NrsRuntimeException("Couldn't load report data.", he);
}
}

Name and version of the database you are using: Postgres 8


===============================================

Problem is the relation between PersistentReportDefinition and PersistentReportData. When executing the method getReportDataById() the query also fetches the PersistentReportDefintion. This makes it slow. I've set the lazy attribute to true ant the outer-join attribute to false.


Why does it still fetch teh PersistentReportDefinition?

Thank you very much 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.