Hibernate version: 3.2CR4 (with Hibernate Annotations 3.2CR2)
Hey all,
I've got a stored procedure I am calling using Annotations. The important parts of the class are below:
Code:
@NamedNativeQuery( name="CountTypes",
query="call QueryCount( :types, :state, :zip, :sort, :fromDay, :toDay )",
resultSetMapping="QueryCount",
hints={ @QueryHint( name="org.hibernate.callable", value="true" ) } )
@SqlResultSetMapping( name="QueryCount",
entities=@EntityResult( entityClass=FilteredCounts.class,
fields={ @FieldResult( name="state", column="STATE" ),
@FieldResult( name="city", column="LOCATION" ),
@FieldResult( name="dm", column="DM" ),
@FieldResult( name="tv", column="TV" ),
@FieldResult( name="ins", column="INS" ),
@FieldResult( name="sw", column="SW" ),
@FieldResult( name="other", column="OTH" ),
@FieldResult( name="total", column="TOTAL" ) } ) )
@Entity
public class FilteredCounts implements Serializable
{
@Id
private String city = null;
@Id
private String state = null;
// ...
}
If I run this as is, then the state field will be null for every record retrieved. If I change the order of the two Ids (so state is on top of city), then the city field will be null for every record retrieved. So it seems to me that Hibernate is ignoring the second Id (which is bad for me). If I choose either city or state, then I will get duplicate records returned for rows that have the same city/state, respectively.
If I make an IdClass:
Code:
@Embeddable
public final class FilteredCountsPK implements Serializable
{
@Column( name="LOCATION" )
private String city = null;
@Column( name="STATE" )
private String state = null;
// ...
}
and I add '@IdClass( FilteredCountsPK.class )' to FilteredCounts I get:
Code:
13:15:18.186 [DEBUG] AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
13:15:18.201 [INFO ] StringType - could not read column value from result set: LOCATION8_0_; An undefined column name was detected.
13:15:18.201 [DEBUG] AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
13:15:18.201 [DEBUG] AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
13:15:18.201 [DEBUG] JDBCExceptionReporter - could not execute query [call QueryCount( ?, ?, ?, ?, ?, ?, ? )]
java.sql.SQLException: An undefined column name was detected.
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:389)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:366)
at com.ibm.as400.access.JDServerRow.findField(JDServerRow.java:390)
at com.ibm.as400.access.AS400JDBCResultSet.findColumn(AS400JDBCResultSet.java:514)
at com.ibm.as400.access.AS400JDBCResultSet.getString(AS400JDBCResultSet.java:3257)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getString(NewProxyResultSet.java:3342)
at org.hibernate.type.StringType.get(StringType.java:18)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.type.ComponentType.hydrate(ComponentType.java:560)
at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:275)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1088)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:553)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
at tlc.dw.rp.FilteredCountsRequestProcessor.retrieve(FilteredCountsRequestProcessor.java:58)
at tlc.dw.rp.RequestProcessor.processStatefulObject(RequestProcessor.java:129)
at tlc.dw.rp.RequestProcessor.processRequest(RequestProcessor.java:83)
at tlc.dw.jms.QueueListener.onMessage(QueueListener.java:103)
at org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:795)
at org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:96)
at org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:149)
at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:110)
at org.apache.activemq.thread.PooledTaskRunner.access$100(PooledTaskRunner.java:25)
at org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Unknown Source)
13:15:18.201 [WARN ] JDBCExceptionReporter - SQL Error: -99999, SQLState: 42703
13:15:18.201 [ERROR] JDBCExceptionReporter - An undefined column name was detected.
13:15:18.201 [DEBUG] ConnectionManager - aggressively releasing JDBC connection
13:15:18.201 [DEBUG] ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
13:15:18.201 [ERROR] FilteredCountsRequestProcessor.retrieve() { dpben:2E2371C42EE27075757047B0783043CC:14486929646393 } - While retrieving FilteredCounts
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
at tlc.dw.rp.FilteredCountsRequestProcessor.retrieve(FilteredCountsRequestProcessor.java:58)
at tlc.dw.rp.RequestProcessor.processStatefulObject(RequestProcessor.java:129)
at tlc.dw.rp.RequestProcessor.processRequest(RequestProcessor.java:83)
at tlc.dw.jms.QueueListener.onMessage(QueueListener.java:103)
at org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:795)
at org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:96)
at org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:149)
at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:110)
at org.apache.activemq.thread.PooledTaskRunner.access$100(PooledTaskRunner.java:25)
at org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: An undefined column name was detected.
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:389)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:366)
at com.ibm.as400.access.JDServerRow.findField(JDServerRow.java:390)
at com.ibm.as400.access.AS400JDBCResultSet.findColumn(AS400JDBCResultSet.java:514)
at com.ibm.as400.access.AS400JDBCResultSet.getString(AS400JDBCResultSet.java:3257)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getString(NewProxyResultSet.java:3342)
at org.hibernate.type.StringType.get(StringType.java:18)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.type.ComponentType.hydrate(ComponentType.java:560)
at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:275)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1088)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:553)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
... 19 more
So Locations isn't being found in the ResultSet anymore...
Here's what the EntityLoader is telling me:
Code:
13:01:27.483 [DEBUG] EntityLoader - Static select for entity tlc.domain.object.mediacount.FilteredCounts: select filteredco0_.LOCATION as LOCATION8_0_, filteredco0_.STATE as STATE8_0_, filteredco0_.dm as dm8_0_, filteredco0_.ins as ins8_0_, filteredco0_.sw as sw8_0_, filteredco0_.tv as tv8_0_, filteredco0_.other as other8_0_, filteredco0_.total as total8_0_ from FilteredCounts filteredco0_ where filteredco0_.LOCATION=? and filteredco0_.STATE=? for read only with rs
Here's how I call the NamedQuery:
Code:
results = session.getNamedQuery( "CountTypes" )
.setParameter( "type", fcl.getType() )
.setParameter( "state", fcl.getState() )
.setParameter( "zip", fcl.getZip() )
.setParameter( "sort", fcl.getSortBy() )
.setParameter( "fromDay", fcl.getFromDay() )
.setParameter( "toDay", fcl.getToDay() )
.list();
Can anyone tell me how I am supposed to use a composite primary key from a NamedNativeQuery (stored procedure)?
Thanks,
~B