-->
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: Problem when loading associated relation
PostPosted: Wed May 21, 2008 5:15 am 
Newbie

Joined: Wed May 21, 2008 2:17 am
Posts: 2
Location: Hong Kong
I've got problem when loading associated relation (the persistent collections) if the datatype of the key is CHAR.

Supposing the length allowed in the key is 32. If the value of the key is just "333", I found that it works fine when using Criteria to retrieve the master entity, but fails when using session.get() to retrieve it. If the value of the key is exactly the same lenght of the datatype (e.g.with 29 spaces behind "333"), it works fine in both cases.

Hibernate version:
hibernate-3.2.6ga

Mapping documents:
Schedule.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class
      name="com.nyklogistics.hk.commons.scheduling.entitybean.Schedule"
      table="SCHEDULE">
      <id name="scheduleId" type="string">
         <column name="SCHEDULE_ID" length="32" />
         <generator class="uuid.hex" />
      </id>
      <version name="version" type="java.lang.Integer">
         <column name="VERSION" />
      </version>
      <many-to-one name="job" update="false" insert="false"
         class="com.nyklogistics.hk.commons.scheduling.entitybean.Job"
         fetch="select">
         <column name="JOB_ID" length="32" />
      </many-to-one>
      <many-to-one name="owner" update="false" insert="false"
         class="com.nyklogistics.hk.commons.security.entitybean.SystemUser"
         fetch="select">
         <column name="OWNER" length="20" />
      </many-to-one>
      <property name="jobId" type="string" not-null="true"
         column="JOB_ID" length="32" />
      <property name="ownerUserId" type="string" not-null="true"
         column="OWNER" length="20" />
      <property name="cronExpression" type="string">
         <column name="CRON_EXPRESSION" length="50" not-null="true" />
      </property>
      <property name="enabled" type="yes_no">
         <column name="ENABLED" length="1" not-null="true" />
      </property>
      <property name="isDeleted" type="yes_no">
         <column name="IS_DELETED" length="1" not-null="true" />
      </property>
      <property name="nextFireTime" type="java.util.Date">
         <column name="NEXT_FIRE_TIME" />
      </property>
      <property name="scheduleMode" type="string">
         <column name="SCHEDULE_MODE" length="10" not-null="true" />
      </property>
      <property name="remark" type="string">
         <column name="REMARK" length="50" />
      </property>
      <property name="scheduleName" type="string">
         <column name="SCHEDULE_NAME" length="250" />
      </property>
      <set name="scheduleLogs" inverse="false">
         <key>
            <column name="SCHEDULE_ID" length="32" />
         </key>
         <one-to-many
            class="com.nyklogistics.hk.commons.scheduling.entitybean.ScheduleLog" />
      </set>
      <set name="scheduleParameters">
         <key>
            <column name="SCHEDULE_ID" length="32" />
         </key>
         <one-to-many
            class="com.nyklogistics.hk.commons.scheduling.entitybean.ScheduleParameter" />
      </set>
   </class>
</hibernate-mapping>

ScheduleLog.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class
      name="com.nyklogistics.hk.commons.scheduling.entitybean.ScheduleLog"
      table="SCHEDULE_LOG">
      <id name="scheduleLogId" type="string">
         <column name="SCHEDULE_LOG_ID" length="32" />
         <generator class="uuid.hex" />
      </id>
      <many-to-one name="schedule" update="false" insert="false"
         class="com.nyklogistics.hk.commons.scheduling.entitybean.Schedule"
         fetch="select">
         <column name="SCHEDULE_ID" length="32" />
      </many-to-one>
      <property name="scheduleId" type="string" column="SCHEDULE_ID" />
      <property name="executionTime" type="java.util.Date">
         <column name="EXECUTION_TIME" length="23" />
      </property>
      <property name="schedulerInstanceId" type="string">
         <column name="SCHEDULER_INSTANCE_ID" length="23" />
      </property>
      <property name="status" type="string">
         <column name="STATUS" length="50" />
      </property>
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
Schedule schedule = (Schedule) session.get(Schedule.class, "333");
System.out.println("##### size = "+schedule.getScheduleLogs().size());

Returns: ##### size = 0

Code:
Criteria c = session.createCriteria(Schedule.class);
c.add(Restrictions.eq("scheduleId", "333"));
Schedule schedule = (Schedule) c.list().get(0);
System.out.println("##### size = "+ schedule.getScheduleLogs().size());

Returns: ##### size = 2

Name and version of the database you are using:
MSSQL Server 2005

The generated SQL (show_sql=true):
Code:
Hibernate: select this_.SCHEDULE_ID as SCHEDULE1_33_0_, this_.VERSION as VERSION33_0_, this_.JOB_ID as JOB3_33_0_, this_.OWNER as OWNER33_0_, this_.CRON_EXPRESSION as CRON5_33_0_, this_.ENABLED as ENABLED33_0_, this_.IS_DELETED as IS7_33_0_, this_.NEXT_FIRE_TIME as NEXT8_33_0_, this_.SCHEDULE_MODE as SCHEDULE9_33_0_, this_.REMARK as REMARK33_0_, this_.SCHEDULE_NAME as SCHEDULE11_33_0_ from SCHEDULE this_ where this_.SCHEDULE_ID=?
Hibernate: select schedulelo0_.SCHEDULE_ID as SCHEDULE2_1_, schedulelo0_.SCHEDULE_LOG_ID as SCHEDULE1_1_, schedulelo0_.SCHEDULE_LOG_ID as SCHEDULE1_34_0_, schedulelo0_.SCHEDULE_ID as SCHEDULE2_34_0_, schedulelo0_.EXECUTION_TIME as EXECUTION3_34_0_, schedulelo0_.SCHEDULER_INSTANCE_ID as SCHEDULER4_34_0_, schedulelo0_.STATUS as STATUS34_0_ from SCHEDULE_LOG schedulelo0_ where schedulelo0_.SCHEDULE_ID=?


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.