Hibernate version: 3.0.5
Mapping documents:
Code:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.carma.console.authorization">
<class name="Authorization" table="AUTH_AUTHORIZATION" lazy="true">
<!-- Meta attributes for code generation -->
<meta attribute="scope-field">protected</meta>
<meta attribute="implement-equals">true</meta><meta attribute="extends">com.carma.console.BaseHibernateObject</meta>
<meta attribute="generated-class">com.carma.console.authorization.model.AbstractAuthorization</meta>
<!-- Id -->
<id name="id" column="AUTHORIZATION_ID" type="long">
<meta attribute="scope-set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<generator class="sequence">
<param name="sequence">AUTHORIZATION_SEQ</param>
</generator>
</id>
<!-- A versioned entity -->
<version name="version" column="VERSION" access="org.hibernate.property.DirectPropertyAccessor">
<meta attribute="scope-field">protected</meta>
<meta attribute="scope-set">protected</meta>
<meta attribute="scope-get">protected</meta>
</version>
<!-- many-to-one name="authAuthorizationTemplate" column="AUTHORIZATION_TEMPLATE_ID" class="AuthorizationTemplate" /-->
<many-to-one name="companyGroup" column="COMPANY_GROUP_ID" class="com.carma.console.authorization.company.CompanyGroup" not-null="true">
<meta attribute="use-in-equals">true</meta>
</many-to-one>
<many-to-one name="documentTypeGroup" column="DOCUMENT_TYPE_GROUP_ID" class="com.carma.console.authorization.doctype.DocumentTypeGroup" not-null="true">
<meta attribute="use-in-equals">true</meta>
</many-to-one>
<many-to-one name="functionGroup" column="FUNCTION_GROUP_ID" class="com.carma.console.authorization.function.FunctionGroup">
<meta attribute="use-in-equals">true</meta>
</many-to-one>
<many-to-one name="role" column="ROLE_ID" class="com.carma.console.authorization.user.Role">
<meta attribute="use-in-equals">true</meta>
</many-to-one>
<many-to-one name="category" column="CATEGORY_ID" class="com.carma.console.common.Category" not-null="true">
<meta attribute="use-in-equals">true</meta>
</many-to-one>
<many-to-one name="user" column="USER_ID" class="com.carma.console.authorization.user.User">
<meta attribute="use-in-equals">true</meta>
</many-to-one>
<property name="statusFlag" column="STATUS_FLAG" type="string" not-null="true" length="1" />
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.carma.console.common">
<class name="Category" table="CATEGORY" lazy="true" mutable="false">
<!-- Meta attributes for code generation -->
<meta attribute="scope-field">protected</meta>
<meta attribute="implement-equals">true</meta><meta attribute="extends">com.carma.console.BaseHibernateObject</meta>
<meta attribute="generated-class">com.carma.console.common.model.AbstractCategory</meta>
<!-- Id -->
<id name="id" column="CATEGORY_ID" type="long">
<meta attribute="scope-set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<generator class="sequence">
<param name="sequence">CATEGORY_SEQ</param>
</generator>
</id>
<set name="documentTypeGroups" cascade="save-update" lazy="true" inverse="true">
<key column="CATEGORY_ID"/>
<one-to-many class="com.carma.console.authorization.doctype.DocumentTypeGroup"/>
</set>
<set name="roles" cascade="save-update" lazy="true" inverse="true">
<key column="CATEGORY_ID"/>
<one-to-many class="com.carma.console.authorization.user.Role"/>
</set>
<set name="documentTypes" cascade="save-update" lazy="true" inverse="true">
<key column="CATEGORY_ID"/>
<one-to-many class="com.carma.console.common.DocumentType"/>
</set>
<set name="functions" cascade="save-update" lazy="true" inverse="true">
<key column="CATEGORY_ID"/>
<one-to-many class="com.carma.console.authorization.function.Function2Category"/>
</set>
<many-to-one name="profileDefinition" column="PROFILE_ID" class="com.carma.console.common.ProfileDefinition" />
<property name="name" column="CATEGORY_NAME" type="string" not-null="true">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>
</class>
</hibernate-mapping>
The generated SQL (show_sql=true):Code:
DEBUG 2005-11-04 09:10:06,009 - select authorizat0_.USER_ID as USER8_1_, authorizat0_.AUTHORIZATION_ID as AUTHORIZ1_1_, authorizat0_.AUTHORIZATION_ID as AUTHORIZ1_0_, authorizat0_.VERSION as VERSION0_0_, authorizat0_.COMPANY_GROUP_ID as COMPANY3_0_0_, authorizat0_.DOCUMENT_TYPE_GROUP_ID as DOCUMENT4_0_0_, authorizat0_.FUNCTION_GROUP_ID as FUNCTION5_0_0_, authorizat0_.ROLE_ID as ROLE6_0_0_, authorizat0_.CATEGORY_ID as CATEGORY7_0_0_, authorizat0_.USER_ID as USER8_0_0_, authorizat0_.STATUS_FLAG as STATUS9_0_0_ from AUTH_AUTHORIZATION authorizat0_ where authorizat0_.USER_ID=?
DEBUG 2005-11-04 09:10:06,109 - select companygro0_.COMPANY_GROUP_ID as COMPANY1_0_, companygro0_.VERSION as VERSION1_0_, companygro0_.NAME as NAME1_0_, companygro0_.STATUS_FLAG as STATUS4_1_0_ from AUTH_COMPANY_GROUP companygro0_ where companygro0_.COMPANY_GROUP_ID=?
DEBUG 2005-11-04 09:10:06,209 - select documentty0_.DOCUMENT_TYPE_GROUP_ID as DOCUMENT1_0_, documentty0_.VERSION as VERSION4_0_, documentty0_.CATEGORY_ID as CATEGORY3_4_0_, documentty0_.NAME as NAME4_0_, documentty0_.STATUS_FLAG as STATUS5_4_0_ from AUTH_DOCUMENT_TYPE_GROUP documentty0_ where documentty0_.DOCUMENT_TYPE_GROUP_ID=?
DEBUG 2005-11-04 09:10:06,300 - select role0_.ROLE_ID as ROLE1_0_, role0_.VERSION as VERSION7_0_, role0_.CATEGORY_ID as CATEGORY3_7_0_, role0_.NAME as NAME7_0_, role0_.STATUS_FLAG as STATUS5_7_0_ from AUTH_ROLE role0_ where role0_.ROLE_ID=?
DEBUG 2005-11-04 09:10:06,400 - select category0_.CATEGORY_ID as CATEGORY1_0_, category0_.PROFILE_ID as PROFILE2_13_0_, category0_.CATEGORY_NAME as CATEGORY3_13_0_ from CATEGORY category0_ where category0_.CATEGORY_ID=?
Hi,
I have an Authorization object refering to a few other objects, eg. Category. Now I load the Authorization object and then want to access the IDs of the refered objects, eg. the category-id. The category class is set to lazy. I thought that the category would only be loaded when i accessed any of the non-id properties because those are obviously not known then, but for some reason even though I only access the Id (which should be known by the authorization-object) hibernate is querying the whole category object in the database.
authorization = (Authorization) authorizations.next();
authorization.getCompanyGroup().getId().toString();
authorization.getCategory().getId().toString();
authorization.getDocumentTypeGroup().getId().toString();
Any comment is appreciated.
Thanks, Ronald