Hi!
I'm trying to use subselect fetching for one-to-many collections. It works fine for loading single objects.
But if I trying to use object with subselect fetch collection in query with named parameters, collection loading fails with еrror "org.hibernate.util.JDBCExceptionReporter - Parameter #1 has not been set."
Detailed information:
I'm using Hibernate 3.0.5
Mapping document:
Code:
<hibernate-mapping>
<class name="ru.masterbit.odc.beans.Client" table="CLIENT" lazy="true">
....
<set name="consultations" fetch="subselect" inverse="true" lazy="true">
<key column="client_id"/>
<one-to-many class="ru.masterbit.odc.beans.ConsultationMicro"/>
</set>
....
</class>
</hibernate-mapping>
Java code:
Code:
this.lastNameHql = "%x%";
String query = "SELECT DISTINCT client FROM Client as client LEFT JOIN client.consultations as cons WHERE client.lastName like :lastNameHql";
Query hibernateQuery = sess.createQuery(query).setProperties(this); // <-- 'this' object have getter getLastNameHql(), so this parameter is definitely present
List clients = hibernateQuery.list(); // <-- Query works fine, parameter :lastNameHql properly passed
Client client = (Client)clients.get(0);
client.getConsultations(); // <-- EXECEPTION HERE !!!
Application log trace:
Code:
Hibernate: /* load one-to-many ru.masterbit.odc.beans.Client.consultations */ select consultati0_.client_id as client4_1_, consultati0_.id as id1_, consultati0_.id as id0_, consultati0_.dateReal as dateReal5_0_, consultati0_.membership_id as membership3_5_0_, consultati0_.client_id as client4_5_0_, consultati0_.cons_id as cons5_5_0_, consultati0_.result as result5_0_, consultati0_.entrust as entrust5_0_ from CONSULTATION_MICRO consultati0_ where consultati0_.client_id in (select client0_.id from CLIENT client0_ left outer join CONSULTATION_MICRO consultati1_ on client0_.id=consultati1_.client_id where client0_.lastName like ?)
[13:51:54.132] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 07000
[13:51:54.148] ERROR org.hibernate.util.JDBCExceptionReporter - Parameter #1 has not been set.
The problem is: class SubselectOneToManyLoader don't overrides Loader.bindNamedParameters(). Default Loader.bindNamedParameters() does nothing.
Possible fix for this problem is to override this method, like class QueryLoader do.
Should I post this request to Hibernate JIRA?
Thank you.
--
Arthur Suilin