-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem with using named queries
PostPosted: Fri Jan 13, 2006 2:29 pm 
Newbie

Joined: Fri Jan 13, 2006 2:13 pm
Posts: 4
Location: Alpharetta, GA
Hello,

I am trying to use a named query to specify rows to return from a table. I get an error that implies that the result set was returned, 1 row was read, then the resultset was closed. It apparently tries to read from the closed result set and sql server shoots off an exception. Any ideas how to fix this?


Mapping:
Code:
      <sql-query name="findEventsByGroup">
         <return alias="r" class="events.TsnEvent" />
         
         select r.*
         from tsn_event r
         where r.tsn_event_group_id = :groupId
         
      </sql-query>


Code that calls it:

Code:
   public List getEventsAgain(){
      
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();      
      
      Query q = session.getNamedQuery("events.TsnEvent.findEventsByGroup")
                      .setParameter("groupId", new Integer(1));
            
      List li = q.list();
      
      session.getTransaction().commit();
      
      return li;
   }


Error:
Code:
11:55:38,515 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
11:55:38,515 DEBUG SessionFactoryObjectFactory:76 - registered: 8a8b86ac08c4b18e0108c4b195130000 (sessionFactory)
11:55:38,530  INFO SessionFactoryObjectFactory:86 - Factory name: sessionFactory
11:55:38,530  INFO NamingHelper:26 - JNDI InitialContext properties:{}
11:55:38,530 DEBUG NamingHelper:48 - binding: sessionFactory
11:55:38,530  WARN SessionFactoryObjectFactory:98 - Could not bind factory to JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
   at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
   at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
   at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
   at javax.naming.InitialContext.getNameParser(Unknown Source)
   at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
   at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:290)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1154)
   at util.HibernateUtil.<clinit>(HibernateUtil.java:13)
   at main.TSNMain.getEventsAgain(TSNMain.java:149)
   at main.TSNMain.main(TSNMain.java:33)
11:55:38,530 DEBUG SessionFactoryImpl:292 - instantiated session factory
11:55:38,546  INFO SessionFactoryImpl:353 - Checking 0 named HQL queries
11:55:38,546  INFO SessionFactoryImpl:373 - Checking 2 named SQL queries
11:55:38,546 DEBUG SessionFactoryImpl:381 - Checking named SQL query: events.EventSummaryReport.findSummaryReportsByDistrict
11:55:38,546 DEBUG QueryPlanCache:111 - unable to locate native-sql query plan in cache; generating (select r.*
         from tsn_v_event_summary_report r
         where tsn_district_id = :districtId)
11:55:38,561 DEBUG SessionFactoryImpl:381 - Checking named SQL query: events.TsnEvent.findEventsByGroup
11:55:38,561 DEBUG QueryPlanCache:111 - unable to locate native-sql query plan in cache; generating (select r.*
         from tsn_event r
         where r.tsn_event_group_id = :groupId)
11:55:38,608 DEBUG SessionImpl:272 - opened session at timestamp: 11371713385
11:55:38,702 DEBUG ThreadLocalSessionContext:282 - allowing method [beginTransaction] in non-transacted context
11:55:38,702 DEBUG JDBCTransaction:54 - begin
11:55:38,702 DEBUG ConnectionManager:313 - opening JDBC connection
11:55:38,702 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
11:55:38,702 DEBUG DriverManagerConnectionProvider:99 - using pooled JDBC connection, pool size: 0
11:55:38,702 DEBUG JDBCTransaction:59 - current autocommit status: false
11:55:38,702 DEBUG JDBCContext:202 - after transaction begin
11:55:38,702 DEBUG QueryPlanCache:117 - located native-sql query plan in cache (select r.*
         from tsn_event r
         where r.tsn_event_group_id = :groupId)
11:55:38,702 DEBUG SessionImpl:1597 - SQL query: select r.*
         from tsn_event r
         where r.tsn_event_group_id = ?
11:55:38,718 DEBUG AbstractBatcher:311 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
11:55:38,718 DEBUG SQL:346 - select r.*
         from tsn_event r
         where r.tsn_event_group_id = ?
Hibernate: select r.*
         from tsn_event r
         where r.tsn_event_group_id = ?
11:55:38,718 DEBUG AbstractBatcher:424 - preparing statement
11:55:38,827 DEBUG Loader:1742 - bindNamedParameters() 1 -> groupId [1]
11:55:38,827 DEBUG IntegerType:79 - binding '1' to parameter: 1
11:55:38,858 DEBUG AbstractBatcher:327 - about to open ResultSet (open ResultSets: 0, globally: 0)
11:55:38,858 DEBUG Loader:682 - processing result set
11:55:38,858 DEBUG Loader:687 - result set row: 0
11:55:38,858 DEBUG IntegerType:123 - returning '1100' as column: tsn_event_id
11:55:38,858 DEBUG Loader:1164 - result row: EntityKey[events.TsnEvent#1100]
11:55:38,858 DEBUG Loader:1347 - Initializing object from ResultSet: [events.TsnEvent#1100]
11:55:38,858 DEBUG AbstractEntityPersister:1860 - Hydrating entity: [events.TsnEvent#1100]
11:55:38,858 DEBUG StringType:123 - returning 'Albuquerque, NM 11/09/2005' as column: name
11:55:38,874 DEBUG StringType:123 - returning 'Recruiting Event' as column: internal_description
11:55:38,874 DEBUG StringType:123 - returning 'Default location' as column: location_description
11:55:38,874 DEBUG IntegerType:123 - returning '1' as column: display_order
11:55:38,890 DEBUG TimestampType:123 - returning '2005-01-01 00:00:00' as column: start_date
11:55:38,890 DEBUG TimestampType:123 - returning '2005-11-09 00:00:00' as column: end_date
11:55:38,890 DEBUG TimestampType:123 - returning '2005-11-09 00:00:00' as column: default_date
11:55:38,890 DEBUG StringType:116 - returning null as column: default_time
11:55:38,890 DEBUG TimestampType:123 - returning '2006-01-05 09:57:43' as column: create_ts
11:55:38,890 DEBUG TimestampType:123 - returning '2006-01-05 09:57:43' as column: update_ts
11:55:38,890 DEBUG StringType:123 - returning '6438' as column: create_user
11:55:38,890 DEBUG StringType:123 - returning '6438' as column: update_user
11:55:38,890 DEBUG AbstractBatcher:334 - about to close ResultSet (open ResultSets: 1, globally: 1)
11:55:38,890 DEBUG AbstractBatcher:319 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
11:55:38,890 DEBUG AbstractBatcher:470 - closing statement
11:55:38,890 DEBUG JDBCExceptionReporter:63 - could not execute query [select r.*
         from tsn_event r
         where r.tsn_event_group_id = ?]
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 3.
   at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
   at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
   at com.microsoft.jdbc.base.BaseResultSet.validateColumnIndex(Unknown Source)
   at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
   at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
   at org.hibernate.type.IntegerType.get(IntegerType.java:28)
   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.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:1899)
   at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1372)
   at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1300)
   at org.hibernate.loader.Loader.getRow(Loader.java:1197)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:569)
   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:2150)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:117)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1607)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:121)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:169)
   at main.TSNMain.getEventsAgain(TSNMain.java:155)
   at main.TSNMain.main(TSNMain.java:33)
11:55:38,890  WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: HY010
11:55:38,890 ERROR JDBCExceptionReporter:72 - [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 3.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.loader.Loader.doList(Loader.java:2153)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:117)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1607)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:121)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:169)
   at main.TSNMain.getEventsAgain(TSNMain.java:155)
   at main.TSNMain.main(TSNMain.java:33)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 3.
   at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
   at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
   at com.microsoft.jdbc.base.BaseResultSet.validateColumnIndex(Unknown Source)
   at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
   at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
   at org.hibernate.type.IntegerType.get(IntegerType.java:28)
   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.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:1899)
   at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1372)
   at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1300)
   at org.hibernate.loader.Loader.getRow(Loader.java:1197)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:569)
   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:2150)
   ... 8 more


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

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.