-->
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: Named Parameter in HBM File
PostPosted: Mon Aug 09, 2010 11:09 am 
Newbie

Joined: Mon May 17, 2010 11:29 am
Posts: 12
I am trying to map a collection within a HBM file using a <sql-query> with named parameters. The Attributes table is keyed by a three member composite key. I want the collection to be populated with attributes when querying on two of those members, the project number and instance number. I can't seem to be able to set the second parameter to the instance number in the project. I need to do this in the hbm file and setting the parameter programmatically is not very desirable. Here is the HBM file. Is this possible since the Project table only has the single primary key?

<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: org.hbm.project.xml 3361 2010-07-23 06:09:52Z pg015113 $ -->
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="true" auto-import="false">
<class name="com.Project" table="Project">
<id name="number" column="Project_Number" />
<property name="instance" column="Instance_Number" />
<bag name="attributes">
<key />
<one-to-many class="com.Attribute" />
<loader query-ref="getAttributes" />
</bag>
</class>
<sql-query name="getAttributes">
<return alias="attribute" class="com.Attribute" />
select * from Attributes where
project_number = :number
and instance_number = :instance
</sql-query>
</hibernate-mapping>

Thanks in advance for any guidance.


Top
 Profile  
 
 Post subject: Re: Named Parameter in HBM File
PostPosted: Mon Aug 09, 2010 2:31 pm 
Newbie

Joined: Mon May 17, 2010 11:29 am
Posts: 12
I decided to step back and try to just get the query to run with the single Proejct_Number parameter set and I'm not having much luck doing just this. If I change my sql-query to this:

<sql-query name="getAttributes">
<load-collection alias="attributes" role="com.Project.attributes" />
<return alias="attribute" class="com.Attribute">
<return-property name="id" >
<return-column name="Project_Property_Number" />
<return-column name="Project_Number" />
<return-column name="Instance" />
</return-property>
</return>
select distinct *
from Project_Properties_List_Inst_Values
where Project_Number = :number
</sql-query>

I get an exception that the id property is not found in the result set. This makes since but how do I tell it that id is not in the result set, but the property name of the composite embedded object to create when recreating each result? Any ideas on this portion? Thanks

edited, forgot to include the stacktrace....

hibernate.SQL select distinct *
from RTMaster.dbo.Project_Properties_List_Inst_Values
where Project_Number = ?
type.IntegerType binding '39' to parameter: 1
type.IntegerType returning '33' as column: Project_Property_Number
type.IntegerType returning '39' as column: Project_Number
type.IntegerType returning '1' as column: Instance
type.IntegerType returning '33' as column: Project_Property_Number
type.IntegerType returning '39' as column: Project_Number
type.IntegerType returning '1' as column: Instance
type.IntegerType could not read column value from result set: id; The column name id is not valid.
util.JDBCExceptionReporter The column name id is not valid.
errors.GrailsExceptionResolver The column name id is not valid.
com.microsoft.sqlserver.jdbc.SQLServerException: The column name id is not valid.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.findColumn(SQLServerResultSet.java:626)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getInt(SQLServerResultSet.java:2219)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:237)
at com.cerner.ipsvc.project.ProjectsController$_closure1_closure5.doCall(ProjectsController.groovy:54)
at com.cerner.ipsvc.project.ProjectsController$_closure1.doCall(ProjectsController.groovy:53)
at com.cerner.ipsvc.project.ProjectsController$_closure1.doCall(ProjectsController.groovy)
at java.lang.Thread.run(Thread.java:619)
[Tomcat].[localhost] Exception Processing ErrorPage[errorCode=500, location=/grails-errorhandler]
java.lang.IllegalStateException: Cannot reset buffer after response has been committed
at org.apache.catalina.connector.Response.resetBuffer(Response.java:691)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:409)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:343)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:287)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)


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.