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.