Hi,
I'm trying to use the Stateless Session but I keep on getting a SessionException telling me that collections cannot be fetched by a stateless session. Now, after reading the documentation on batch operations, I thought that collections within objects would just be ignored.
Any input on using the stateless session would be greatly appreciated!
Thanks,
Allan
Hibernate version: 3.2.3ga
Mapping documents:
<query name="findLocationByName"><![CDATA[
from Location location left join fetch location.address left join fetch location.settings left join fetch location.group where location.name = ?
]]></query>
Code between sessionFactory.openSession() and session.close():
StatelessSession statelessSession = getHibernateTemplate().getSessionFactory().openStatelessSession();
// Get queries we need
Query locationQuery = statelessSession.getNamedQuery("findLocationByName");
District district = getFirstDistrict();
for (School school : allSchools) {
locationQuery.setParameter(0, school.getName(), Hibernate.STRING);
Location existingLocation = (Location) locationQuery.uniqueResult(); <== Failing here
Full stack trace of any exception that occurs:
org.hibernate.SessionException: collections cannot be fetched by a stateless session
at org.hibernate.impl.StatelessSessionImpl.initializeCollection(StatelessSessionImpl.java:226)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:785)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:241)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.StatelessSessionImpl.list(StatelessSessionImpl.java:467)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)
at net.riverdeep.data.eis.support.HibernateStatelessSessionBulkOperationsDAO.saveSchools(HibernateStatelessSessionBulkOperationsDAO.java:333)
Name and version of the database you are using: MySQL 5.0.23
The generated SQL (show_sql=true):
Hibernate: select location0_.PK_LOCATION_ID as PK1_45_0_, address1_.PK_ADDRESS_ID as PK1_79_1_, settings2_.PK_SETTING_ID as PK1_12_2_, group3_.PK_GROUP_ID as PK1_38_3_, location0_.FK_GROUP_ID as FK3_45_0_, location0_.NAME as NAME45_0_, location0_.FK_ADDRESS_ID as FK5_45_0_, location0_.ENTERPRISE_ID as ENTERPRISE6_45_0_, location0_.SCHOOL_ID as SCHOOL7_45_0_, location0_.FK_DISTRICT_ID as FK8_45_0_, location0_.LOCATION_TYPE as LOCATION2_45_0_, address1_.COUNTY as COUNTY79_1_, address1_.ADDRESS1 as ADDRESS3_79_1_, address1_.ADDRESS2 as ADDRESS4_79_1_, address1_.CITY as CITY79_1_, address1_.FK_COUNTRY_ID as FK6_79_1_, address1_.ZIP_CODE as ZIP7_79_1_, address1_.FK_STATE_PROV_REG_ID as FK8_79_1_, settings2_.NAME as NAME12_2_, settings2_.VALUE as VALUE12_2_, settings2_.LOCATION_ID as LOCATION4_0__, settings2_.PK_SETTING_ID as PK1_0__, group3_.NAME as NAME38_3_, group3_.DESCRIPTION as DESCRIPT4_38_3_, group3_.CREATED as CREATED38_3_, group3_.FK_PARENTGROUP_ID as FK6_38_3_, group3_.FK_USER_ID as FK7_38_3_, group3_.GRADE as GRADE38_3_, group3_.USER_TYPE as USER9_38_3_, group3_.GROUP_TYPE as GROUP2_38_3_ from LMS_LOCATION location0_ left outer join LMS_ADDRESS address1_ on location0_.FK_ADDRESS_ID=address1_.PK_ADDRESS_ID left outer join LMS_SETTING settings2_ on location0_.PK_LOCATION_ID=settings2_.LOCATION_ID left outer join LMS_GROUP group3_ on location0_.FK_GROUP_ID=group3_.PK_GROUP_ID where location0_.NAME=?
|