IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes Hibernate hql list filter Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate hql list filter" Watch "Hibernate hql list filter" New topic
Author

Hibernate hql list filter

gustavo sanchez
Greenhorn

Joined: May 18, 2007
Posts: 5
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

Joined: Feb 05, 2001
Posts: 16622

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
gustavo sanchez
Greenhorn

Joined: May 18, 2007
Posts: 5
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 ]
 
 
subject: Hibernate hql list filter
 
Threads others viewed
persisting a collection - one-to-many mapping
Repeated updates on EVENT table, in Hibernate one to many mapping
joins in Hibernate Annotation
Use of set tag in Hibernate mapping file?
Hibernate, User and Address with association table between
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com