• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate hql list filter

 
gustavo sanchez
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to filter using an array of objects, because sometimes is many to many or one to many the kind of object that i need to filter. I'm using the flowing code :

...getSession().createQuery("from Person where addresses in ( :L0)");
qry.setParameterList("L0", (Collection)val);

val is an arrayList... of Objects "Address"

and hibernate create that query:

Hibernate: select person0_.id as id21_, person0_1_.customerId as customerId21_, person0_.documentNumber as document2_26_, person0_.firstName as firstName26_, person0_.lastName as lastName26_, person0_.email as email26_, person0_.companyId as companyI
d26_ from persons person0_ inner join contacts person0_1_ on person0_.id=person0_1_.id, contact_addresses addresses1_, addresses address2_ where person0_.id=addresses1_.contactId and addresses1_.addressId=address2_.id and ({non-qualified-property-ref
} in (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?))

the query contains an {non-qualified-property-ref} ... but the mapping appear to be ok, i dont know what kind of error im having in that code or mapping

thats the involved part of the mapping file

<class name="Contact" table="contacts" abstract="true" polymorphism="explicit">
<id name="id" type="long">
<generator class="native"/>
</id>
<set name="addresses" table="contact_addresses" cascade="all">
<key column="contactId"/>
<many-to-many column="addressId" class="Address"/>
</set>
.....
<joined-subclass name="Person" table="persons">
<key column="id"/>
<property name="documentNumber"/>
<property name="firstName"/>
<property name="lastName"/>
<property name="email"/>
<many-to-one name="company" column="companyId"/>
</joined-subclass>
</class>

<class name="Address" table="addresses">
<id name="id" >
<generator class="native"/>
</id>
....
<property name="city"/>
....
</class>


then, i got a exception....

11:00:09,625 WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: 07001
11:00:09,640 ERROR JDBCExceptionReporter:78 - No value specified for parameter 1
11:00:09,656 WARN RequestProcessor:528 - Unhandled Exception thrown: class org.hibernate.exception.SQLGrammarException
11:00:09,687 ERROR [action]:250 - Servlet.service() para servlet action lanz� excepci�n
java.sql.SQLException: No value specified for parameter 1

I hope that to be posible to do in hibernate, but im not sure how to do that... if someone know, it will appreciate the help
[ May 18, 2007: Message edited by: gustavo sanchez ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What it is says is this

"from Person where addresses"

So "addresses" It is not qualified. Where does addresses come from. Usually you would have the following

"from Person p where p.addresses"

See the adding of the alias "p". That is qualifying addresses to say addresses comes from the Person object referencing it.

Mark
 
gustavo sanchez
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, it sounds good, but is not working, now, hibernate traslate the query in that way :
".....dress2_.id and (. in (? , ? , ? , ? , ? , ?
, ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?))"

the field is called by hibernate ".", and i send to hibernate in hql :
"from Person act where act.addresses in (:V0)"

the traslated query, must have the pivot table (many to many).... but i dont know how to tell to hql "thats a collection of Addresses, you must use pivot table"
[ May 21, 2007: Message edited by: gustavo sanchez ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic