-->
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.  [ 2 posts ] 
Author Message
 Post subject: sql-query problems using individual properties to load Set
PostPosted: Sat Apr 16, 2011 1:39 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:30 pm
Posts: 46
Location: Fortaleza, Brazil
Hi all, I am running hibernate 3.5.4 with SQL Server 2008, and I cannot get past this error:

Code:
2011-04-16 11:01:20,314 [org.hibernate.util.JDBCExceptionReporter] - could not execute query [SELECT assetNotesID AS assetNotesID, 
           obj_version AS obj_version,                           
           subject AS subject,                                   
           source AS source,                                     
           notes AS notes,                                       
           attachedFileSizeInBytes AS attachedFileSizeInBytes,   
           attachedFileName AS attachedFileName,                 
           created AS created,                                   
           modified AS modified,                                 
           createdUserID AS createdUserID,                       
           modifiedUserID AS modifiedUserID,                     
           deleted AS deleted,                                   
           alias1.assetID AS assetID,                             
           NULL AS attachedFile                                   
    from AssetNotes alias1 where assetID = ?]                     
com.microsoft.sqlserver.jdbc.SQLServerException: The column name assetID9_5_0_ is not valid.


I also tried to tweak <sql-query> to send "assetID AS assetID" , and that didn't help.

I have two requirements: (1) ignore a column, the binary attachedFile on the Set of assetNotes side. The plan I have is to simply return "NULL as attachedFile" as the sql. And (2) use "SELECT TOP 2" for row limiting. For now I'm just trying to load all the columns individually and go from there. I am trying to populate Set assetNotes in this file:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.wazollc.alphatheory.hibernate.bo">
   <class name="AssetBO"
               table="`ASSET`"
               dynamic-update="false"
               dynamic-insert="false"
               select-before-update="false"
               optimistic-lock="version"
               lazy="false"
               batch-size="300"
        >
      <id name="id" type="java.lang.Long" column="`assetID`">
                        <generator class="native">
                        </generator>
      </id>
                <version name="version" type="java.lang.Long" access="field" column="OBJ_VERSION"/>


       <property name="modified" column="`modified`" type="timestamp"                         
                                not-null="true" length="6" />   

                 <property name="created" column="`created`"                                                         
                        type="timestamp"                         
                                not-null="true" length="6" />

                <many-to-one
                        name="createdUser"
                        column="`createdUserID`"
                        class="com.wazollc.alphatheory.hibernate.bo.ATUserBO"
                        not-null="true"/>

               <many-to-one
                        name="modifiedUser"
                        column="`modifiedUserID`"
                        class="com.wazollc.alphatheory.hibernate.bo.ATUserBO"
                        not-null="true"/>
               
               
                                               
      <property name="deleted" column="`deleted`"
         type="java.lang.Boolean" not-null="false" />


                <set name="assetNotes" fetch="subselect" table="`assetNotes`" inverse="true" cascade="all-delete-orphan" order-by="`modified` desc" lazy="true">
                       <key column="`assetID`" />
                       <one-to-many class="com.wazollc.alphatheory.hibernate.bo.AssetNotesBO" />
                       <loader query-ref="assetNotesLoader"/>
                       <filter name="deletedFilter"/>
                </set>

      <filter name="deletedFilter"/>
   </class>

       <sql-query name="assetNotesLoader">                       
    <return alias="alias1" class="AssetNotesBO">                 
        <return-property name="id" column="assetNotesID"/>       
        <return-property name="version" column="obj_version"/>   
        <return-property name="subject" column="subject"/>   
        <return-property name="source" column="source"/>   
        <return-property name="notes" column="notes"/>   
        <return-property name="attachedFileSizeInBytes" column="attachedFileSizeInBytes"/>   
        <return-property name="attachedFileName" column="attachedFileName"/>   
        <return-property name="created" column="created"/>   
        <return-property name="modified" column="modified"/>   
        <return-property name="createdUserID" column="createdUserID"/>   
        <return-property name="modifiedUserID" column="modifiedUserID"/>   
        <return-property name="deleted" column="deleted"/>   
        <return-property name="assetID" column="assetID"/>   
        <return-property name="attachedFile" column="attachedFile"/>   
    </return><![CDATA[                                           
    SELECT assetNotesID AS {alias1.id},
           obj_version AS {alias1.version},
           subject AS {alias1.subject},
           source AS {alias1.source},
           notes AS {alias1.notes},
           attachedFileSizeInBytes AS {alias1.attachedFileSizeInBytes},
           attachedFileName AS {alias1.attachedFileName},
           created AS {alias1.created},
           modified AS {alias1.modified},
           createdUserID AS {alias1.createdUserID},
           modifiedUserID AS {alias1.modifiedUserID},
           deleted AS {alias1.deleted},
           alias1.assetID AS {alias1.assetID},
           attachedFile AS {alias1.attachedFile}
    from AssetNotes alias1 where alias1.assetID = :id             
    ]]></sql-query>   
   
</hibernate-mapping>


Here's the hbm file for assetNotes:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.wazollc.alphatheory.hibernate.bo">
   <class name="AssetNotesBO"
               table="`ASSETNOTES`"
               dynamic-update="false"
               dynamic-insert="false"
               select-before-update="false"
               optimistic-lock="version"
               lazy="true"
               batch-size="6"
        >
      <id name="id" type="java.lang.Long" column="`assetNotesID`">
                        <generator class="native">
                        </generator>
      </id>
        <version name="version" type="java.lang.Long" access="field" column="OBJ_VERSION"/>


      <property name="subject" column="`subject`"
                        type="java.lang.String"
                        length="2000"
         not-null="false" />

      <property name="source" column="`source`"
                        type="java.lang.String"
                        length="2000"
         not-null="false" />
         
               <property name="notes" column="`notes`"
                        type="text"
         not-null="false" />

         <property name="attachedFile"
         type="binary" length="1000000000"/>
         
         
      <property name="attachedFileSizeInBytes" column="`attachedFileSizeInBytes`"
         type="java.lang.Long" not-null="false" />


      <property name="attachedFileName" column="`attachedFileName`"
         type="java.lang.String" not-null="false" length="500" />

         
                <many-to-one
                        name="asset"
                        column="`assetID`"
                        cascade="save-update"
                        class="com.wazollc.alphatheory.hibernate.bo.AssetBO"
                        not-null="true"
                        />

            <property name="created" column="`created`"
                        type="timestamp"
            not-null="true" length="6" />
         
            <property name="modified" column="`modified`"
                        type="timestamp"
            not-null="true" length="6" />
         
                <many-to-one
                        name="createdUser"
                        column="`createdUserID`"
                        class="com.wazollc.alphatheory.hibernate.bo.ATUserBO"
                        not-null="true"/>

               <many-to-one
                        name="modifiedUser"
                        column="`modifiedUserID`"
                        class="com.wazollc.alphatheory.hibernate.bo.ATUserBO"
                        not-null="true"/>

            <property name="deleted" column="`deleted`"
               type="java.lang.Boolean" not-null="false" />
                               
            <filter name="deletedFilter"/>                       
   </class>
</hibernate-mapping>



I tried with both load-collection and the example above and assetID is always the problem in the <sql-query>. Please help.


Top
 Profile  
 
 Post subject: Re: sql-query problems using individual properties to load Set
PostPosted: Thu Apr 21, 2011 8:15 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:30 pm
Posts: 46
Location: Fortaleza, Brazil
I compiled from source and added this log to Loader.java:

Code:
if ( log.isDebugEnabled() ) {                                             
                    log.debug("loadFromResultSet cols: " + Arrays.deepToString(cols));   
                }     


And I see that the 3 columns that are fk's are getting aliased:

Code:
2011-04-21 20:08:13,880 DEBUG [org.hibernate.loader.Loader] (http-0.0.0.0-8080-4) loadFromResultSet cols: [[obj_version], [subject], [source], [notes], [attachedFile], [attachedFileSizeInBytes], [attachedFileName], [assetID9_5_0_], [created], [modified], [created12_5_0_], [modifie13_5_0_], [deleted]]           
2011-04-21 20:08:13,886 INFO  [org.hibernate.type.LongType] (http-0.0.0.0-8080-4) could not read column value from result set: assetID9_5_0_; The column name assetID9_5_0_ is not valid.


I tried joins on those columns in <sql-query> and it didn't help. Any ideas how to stop this aliasing when using sql-query?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.