-->
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.  [ 3 posts ] 
Author Message
 Post subject: Binding a list argument in queries?
PostPosted: Mon Oct 24, 2005 12:00 pm 
Beginner
Beginner

Joined: Tue Nov 25, 2003 3:33 pm
Posts: 35
Hibernate version: 3.1rc2

I have some query trouble. I have a query where my parameter is list of Long's.

Anyway here the query:
from Holiday h where h.type = :calendarType and h.year in (:calendarYears)

and here is the SQL it generates:
Code:
select
   holiday0_.id as id14_,
   holiday0_.version as version14_,
   holiday0_.calendar as calendar14_,
   holiday0_.hol_date as hol4_14_,
   holiday0_.year as year14_,
   holiday0_.description as descript6_14_
from holidays holiday0_ where holiday0_.calendar=? and
       (holiday0_.year in (?))


which is correct.

here is a portion of the traces with debug ON that shows that list does exists:
Code:
org.hibernate.impl.SessionImpl find: from Holiday h where h.type = :calendarType and h.year in (:calendarYears)
org.hibernate.util.SerializationHelper Starting serialization of object [[2005, 2006]]
org.hibernate.engine.QueryParameters named parameters: {calendarType=O, calendarYears=2c6d8085f3f28093eae1f6e1aef5f4e9ecaec1f2f2e1f9cce9f3f4f801529d1947e11d838081c98084f3e9fae5f8f080808082f7848080808af3f2808eeae1f6e1aeece1eee7aeccefeee7bb0b64104c0fa35f828081ca8085f6e1ecf5e5f8f28090eae1f6e1aeece1eee7aecef5ede2e5f2062c159d8b14600b828080f8f08080808080808755f3f180fe80828080808080808756f8}
org.hibernate.hql.ast.QueryTranslatorImpl compile() : The query is already compiled, skipping...
org.hibernate.jdbc.AbstractBatcher about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
org.hibernate.SQL select holiday0_.id as id14_, holiday0_.version as version14_, holiday0_.calendar as calendar14_, holiday0_.hol_date as hol4_14_, holiday0_.year as year14_, holiday0_.description as descript6_14_ from holidays holiday0_ where holiday0_.calendar=? and (holiday0_.year in (?))
Hibernate: select holiday0_.id as id14_, holiday0_.version as version14_, holiday0_.calendar as calendar14_, holiday0_.hol_date as hol4_14_, holiday0_.year as year14_, holiday0_.description as descript6_14_ from holidays holiday0_ where holiday0_.calendar=? and (holiday0_.year in (?))
org.hibernate.jdbc.AbstractBatcher preparing statement
org.hibernate.loader.Loader bindNamedParameters() O -> calendarType [1]
org.hibernate.type.StringType binding 'O' to parameter: 1
org.hibernate.loader.Loader bindNamedParameters() [2005, 2006] -> calendarYears [2]
org.hibernate.util.SerializationHelper Starting serialization of object [[2005, 2006]]
org.hibernate.type.SerializableType binding '2c6d8085f3f28093eae1f6e1aef5f4e9ecaec1f2f2e1f9cce9f3f4f801529d1947e11d838081c98084f3e9fae5f8f080808082f7848080808af3f2808eeae1f6e1aeece1eee7aeccefeee7bb0b64104c0fa35f828081ca8085f6e1ecf5e5f8f28090eae1f6e1aeece1eee7aecef5ede2e5f2062c159d8b14600b828080f8f08080808080808755f3f180fe80828080808080808756f8' to parameter: 2
org.hibernate.util.SerializationHelper Starting serialization of object [[2005, 2006]]
org.hibernate.jdbc.AbstractBatcher about to open ResultSet (open ResultSets: 0, globally: 0)
org.hibernate.loader.Loader processing result set
org.hibernate.loader.Loader done processing result set (0 rows)
org.hibernate.jdbc.AbstractBatcher about to close ResultSet (open ResultSets: 1, globally: 1)
org.hibernate.jdbc.AbstractBatcher about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
org.hibernate.jdbc.AbstractBatcher closing statement
org.hibernate.loader.Loader total objects hydrated: 0
org.hibernate.engine.StatefulPersistenceContext initializing non-lazy collections
org.hibernate.transaction.JDBCTransaction commit
org.hibernate.impl.SessionImpl automatically flushing session



but for some reason Hibernate tries to serialize the list and binds the serialized string to calendarYears. As shown in trace above like this:
Code:
{calendarType=O, calendarYears=2c6d8085f3f28093eae1f6e1aef5f4e9ecaec1f2f2e1f9cce9f3f4f801529d1947e11d838081c98084f3e9fae5f8f080808082f7848080808af3f2808eeae1f6e1aeece1eee7aeccefeee7bb0b64104c0fa35f828081ca8085f6e1ecf5e5f8f28090eae1f6e1aeece1eee7aecef5ede2e5f2062c159d8b14600b828080f8f08080808080808755f3f180fe80828080808080808756f8}


That of course returns 0 sized result which is not correct.

So how do I do it?

Thanks,
Alex.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 2:39 pm 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
Are you using the setParameterList method of the query Interface? Without that hibernate doesn't know that calendarYears should be treated as a list.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 2:43 pm 
Beginner
Beginner

Joined: Tue Nov 25, 2003 3:33 pm
Posts: 35
excellent, thanks that worked :-)


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