-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 3 series Native Query .list() returns null objects
PostPosted: Tue Nov 15, 2005 11:47 am 
Newbie

Joined: Mon Feb 07, 2005 3:46 pm
Posts: 5
I switched to using Hibernate 3 series code recently, but didn't notice this problem untill just today. I am constructing a fully native query, and doing the following code:
Code:
            q = session.createSQLQuery(queryString);
            q.addEntity("cat_result", CategorySearchResultImpl.class);

            q.setInteger("region", getRegionMCA());
            q.setInteger("system", getSystemMCA());
            q.setInteger("mso", getMSOMCA());
            q.setInteger("headend", getHeadendMCA());
            q.setInteger("payload_id", getDataVersion());
            q.setInteger("sub_category_id", getSubCategory());
            q.setInteger("current_time", s_timeUtility.getCurrentGMTMinute(queryTime));
            q.setInteger("start_time", s_timeUtility.getLowRangeGMTMinute(queryTime));
            q.setInteger("end_time", s_timeUtility.getHighRangeGMTMinute(queryTime));

            List myList = q.list();


The list comes back with the correct length for the result set, but all the items in the list are null and I just can NOT figure out why. The Mapping document is comprised of a single LARGE composite key which is read only and can not be persisted back to the database (due to the nature of the query being a multi-table join). Someone PLEASE help - I am confused and lost, it appears that I am doing what I need to, to execute this query (I don't get any exceptions or errors in the process) I just don't get the results - just the empty list of correct length.

Thanks in advance.
Joe Campbell

Hibernate version:3.0.5/3.1 rc2

Mapping documents:
Code:
<hibernate-mapping>
    <class name="com.gnet.gds.schema.category.impl.CategorySearchResultImpl" lazy="false">

        <cache usage="read-only"/>

        <composite-id>
            <key-property name="ProgramType" column="program_type" type="integer"/>
            <key-property name="programId" column="program_id" type="integer"/>
            <key-property name="title" column="program_title" type="string"/>
            <key-property name="TVRating" column="tv_rating" type="integer"/>
            <key-property name="MPAARating" column="mpaa_rating" type="integer"/>
            <key-property name="category" column="category" type="integer"/>
            <key-property name="sourceId" column="source_id" type="integer"/>
            <key-property name="startTime" column="start_time" type="integer"/>
            <key-property name="assetId" column="asset_id" type="string"/>
            <key-property name="providerId" column="provider_id" type="string"/>
            <key-property name="duration" column="duration" type="string"/>
            <key-property name="price" column="price" type="float"/>
            <key-property name="HDTV" column="hdtv_flag" type="boolean"/>
            <key-property name="newRelease" column="newrelease_flag" type="boolean"/>
            <key-property name="wideScreen" column="widescreen_flag" type="boolean"/>
            <key-property name="lastChance" column="lastchance_flag" type="boolean"/>
            <key-property name="dolby51" column="dolby_flag" type="boolean"/>
            <key-property name="closeCaption" column="closedcaption_flag" type="boolean"/>
            <key-property name="free" column="free_flag" type="boolean"/>
            <key-property name="SVOD" column="SVOD_flag" type="boolean"/>

        </composite-id>
    </class>
</hibernate-mapping>



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

Full stack trace of any exception that occurs: There is no exception just some very strange behaviour.

Name and version of the database you are using: Oracle 10g

The generated SQL (show_sql=true):
Code:
WITH A as
(SELECT 64 as record_type,
       min(p.program_id) as program_id,
       ps.long_title,
       p.tv_rating,
       p.mpaa_rating,
       p.category,
       min(sch.source_id) as source_id,
       sch.start_time,
       null,
       null,
       to_char(sch.duration) as duration,
       0.00,
       0,
       0,
       0,
       0,
       0,
       0,
       0,
       p.series_id
  FROM PROGRAM p,
       PROGRAM_STRING ps,
       PROGRAM_CATEGORY pc,
       SCHEDULE sch,
       SERVICE ser
WHERE ((ser.hardware_address = 0)
        OR (ser.hardware_address = ?)
        OR (ser.hardware_address = ?)
        OR (ser.hardware_address = ?)
        OR (ser.hardware_address = ?))
   AND ser.payload_id    = sch.payload_id
   AND ser.payload_id    = pc.payload_id
   AND ser.source_id     = sch.source_id
   AND ser.payload_id    = ps.payload_id
   AND pc.payload_id     = ?
   AND pc.subcategory_id = ?
   AND pc.payload_id     = p.payload_id
   AND pc.program_id     = sch.program_id
   AND p.program_id      = sch.program_id
   AND p.program_id      = ps.program_id
   AND p.event_type      < 4
   AND p.list_by_title   > 0
   AND sch.start_time >= ?
   AND sch.start_time <= ?
   AND ((sch.start_time + sch.duration) - ?) > 15
   AND p.series_id       > 0
GROUP BY ps.long_title,
         p.tv_rating,
         p.mpaa_rating,
         p.category,
         sch.duration,
         sch.start_time,
         p.series_id),
B as
(SELECT 64 as record_type,
       min(p.program_id) as program_id,
       ps.long_title,
       p.tv_rating,
       p.mpaa_rating,
       p.category,
       min(sch.source_id) as source_id,
       sch.start_time,
       null,
       null,
       to_char(sch.duration) as duration,
       0.00,
       0,
       0,
       0,
       0,
       0,
       0,
       0
  FROM PROGRAM p,
       PROGRAM_STRING ps,
       PROGRAM_CATEGORY pc,
       SCHEDULE sch,
       SERVICE ser
WHERE ((ser.hardware_address = 0)
        OR (ser.hardware_address = ?)
        OR (ser.hardware_address = ?)
        OR (ser.hardware_address = ?)
        OR (ser.hardware_address = ?))
   AND ser.payload_id    = sch.payload_id
   AND ser.payload_id    = pc.payload_id
   AND ser.source_id     = sch.source_id
   AND ser.payload_id    = ps.payload_id
   AND pc.payload_id     = ?
   AND pc.subcategory_id = ?
   AND pc.payload_id     = p.payload_id
   AND pc.program_id     = sch.program_id
   AND p.program_id      = sch.program_id
   AND p.program_id      = ps.program_id
   AND p.event_type      < 4
   AND p.list_by_title   > 0
   AND sch.start_time >= ?
   AND sch.start_time <= ?
   AND ((sch.start_time + sch.duration) - ?) > 15
   AND p.series_id       = 0
GROUP BY ps.long_title,
         p.tv_rating,
         p.mpaa_rating,
         p.category,
         sch.duration,
         sch.start_time)
SELECT A.record_type  as program1_4_0_,
       A.program_id   as program2_4_0_,
       A.long_title   as program3_4_0_,
       A.tv_rating    as tv4_4_0_,
       A.mpaa_rating  as mpaa5_4_0_,
       A.category     as category4_0_,
       A.source_id    as source7_4_0_,
       A.start_time   as start8_4_0_,
       null           as asset9_4_0_,
       null           as provider10_4_0_,
       A.duration     as duration4_0_,
       0.00           as price4_0_,
       0              as hdtv13_4_0_,
       0              as newrelease14_4_0_,
       0              as widescreen15_4_0_,
       0              as lastchance16_4_0_,
       0              as dolby17_4_0_,
       0              as closedc18_4_0_,
       0              as free19_4_0_,
       0              as SVOD20_4_0_
  FROM A
WHERE (A.series_id, A.start_time) in (
   SELECT A1.series_id, min(A1.start_time)
     FROM A A1
GROUP BY A1.series_id)
  UNION
SELECT B.record_type  as program1_4_0_,
       B.program_id   as program2_4_0_,
       B.long_title   as program3_4_0_,
       B.tv_rating    as tv4_4_0_,
       B.mpaa_rating  as mpaa5_4_0_,
       B.category     as category4_0_,
       B.source_id    as source7_4_0_,
       B.start_time   as start8_4_0_,
       null           as asset9_4_0_,
       null           as provider10_4_0_,
       B.duration     as duration4_0_,
       0.00           as price4_0_,
       0              as hdtv13_4_0_,
       0              as newrelease14_4_0_,
       0              as widescreen15_4_0_,
       0              as lastchance16_4_0_,
       0              as dolby17_4_0_,
       0              as closedc18_4_0_,
       0              as free19_4_0_,
       0              as SVOD20_4_0_
  FROM B
WHERE (B.program_id, B.start_time) in (
   SELECT B1.program_id, min(B1.start_time)
     FROM B B1
GROUP BY B1.program_id)
UNION ALL
SELECT 65 as program1_4_0_,
       0 as program2_4_0_,
       vodtmd.title as program3_4_0_,
       vodtrm.value as tv4_4_0_,
       0 as mpaa5_4_0_,
       CASE
          WHEN vodg.ITHEME_ID <= 99 THEN 0
          WHEN vodg.ITHEME_ID between (100) AND (199) THEN 1
          WHEN vodg.ITHEME_ID between (200) AND (299) THEN 2
          WHEN vodg.ITHEME_ID between (300) AND (399) THEN 3
       END as category4_0_,
       0 as source7_4_0_,
       0 as start8_4_0_,
       vodt.asset_id  as asset9_4_0_,
       vodt.provider_id as provider10_4_0_,
       vodtmd.display_run_time as duration4_0_,
       vodtmd.price as price4_0_,
       CASE
          WHEN vodmmd.hd_content = 'Y' then 1
          ELSE 0
       END as hdtv13_4_0_,
       vodtmd.display_as_new as newrelease14_4_0_,
       CASE
          WHEN vodmmd.screen_format in ('Widescreen', 'Letterbox') then 1
          ELSE 0
       END as widescreen15_4_0_,
       vodtmd.display_as_last_chance as lastchance16_4_0_,
       CASE
          WHEN vodmpat.audio_type = ('Dolby Digital')  then 1
          ELSE 0
       END as dolby17_4_0_,
       CASE
          WHEN vodtmd.closed_captioning is null then 0
          ELSE 0
       END as closedc18_4_0_,
       CASE
          WHEN vodtmd.free = 'Y' then 1
          ELSE 0
       END as free19_4_0_,
       CASE
            WHEN vodtmd.IS_SVOD = 'Y' then 1
            ELSE 0
       END as SVOD20_4_0_
  FROM title vodt,
       title_app_md vodtmd,
       title_rating vodtr,
       title_rating_map vodtrm,
       VOD_ITHEME_FINAL vodg,
       movie_app_md vodmmd,
       movie_preview_audio_type vodmpat,
       asset voda
WHERE vodtmd.TITLE_ID    = vodt.ID
   AND vodtmd.adult       = 'N'
   AND vodtmd.hidden      = 'N'
   AND vodtr.TITLE_ID     = vodt.ID
   AND vodg.TITLE_ID      = vodt.ID
   AND vodg.ITHEME_ID     = ?
   AND voda.title_id      = vodt.ID
   AND vodmmd.movie_id    = voda.ID
   AND vodmpat.movie_id   = vodmmd.movie_id
   AND vodtr.rating       = vodtrm.rating
   AND voda.asset_type_id = 3
   ORDER BY program3_4_0_, program1_4_0_ desc, start8_4_0_



Debug level Hibernate log excerpt: N/A


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 11:59 am 
Newbie

Joined: Tue Nov 15, 2005 11:55 am
Posts: 1
If any of the elements specified in the composite id has a NULL value. The List will have a null value.


Top
 Profile  
 
 Post subject: yup - just discovered that...
PostPosted: Tue Nov 15, 2005 12:31 pm 
Newbie

Joined: Mon Feb 07, 2005 3:46 pm
Posts: 5
I was just finishing up a serious little debugging session and found that.

Shouldn't this throw and exception and not just return a null object when it attempts to hydrate the object?

The line in question would be the if (isKey) line... I would think that this should throw an exception not return null. If a 'KEY' item in an object came back from the DB as null - and hibernate is expecting that to not BE null I would call that an exception.

Do you happen to know what the rational for returning null here is?

Code:
   public Object hydrate(
         final ResultSet rs,
         final String[] names,
         final SessionImplementor session,
         final Object owner)
   throws HibernateException, SQLException {

      int begin = 0;
      boolean notNull = false;
      Object[] values = new Object[propertySpan];
      for ( int i = 0; i < propertySpan; i++ ) {
         int length = propertyTypes[i].getColumnSpan( session.getFactory() );
         String[] range = ArrayHelper.slice( names, begin, length ); //cache this
         Object val = propertyTypes[i].hydrate( rs, range, session, owner );
         if ( val == null ) {
            if (isKey) return null; //different nullability rules for pk/fk
         }
         else {
            notNull = true;
         }
         values[i] = val;
         begin += length;
      }

      return notNull ? values : null;
   }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.