-->
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: Collection error when using Stateless Session
PostPosted: Tue Jun 05, 2007 8:30 pm 
Newbie

Joined: Tue Jun 05, 2007 7:44 pm
Posts: 2
Location: Atlanta, GA
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=?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 06, 2007 3:54 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hi,

can you post the mappings of the classes that you use in the query.
Perhaps there are some collection mappings in them,
that make problems to hibernate.

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 06, 2007 8:54 am 
Newbie

Joined: Tue Jun 05, 2007 7:44 pm
Posts: 2
Location: Atlanta, GA
Ooops, sorry! Here's the mapping file:


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="..Location"
table="..LOCATION"
discriminator-value="Location"
>

<id
name="id"
column="PK_LOCATION_ID"
type="java.lang.String"
length="32"
unsaved-value="null"
>
<generator class="uuid.hex"/>
</id>

<discriminator
column="LOCATION_TYPE"
type="string"
length="50"
/>

<many-to-one
name="group"
class="..Group"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="FK_GROUP_ID"
/>

<property
name="name"
type="string"
update="true"
insert="true"
column="NAME"
length="60"
not-null="true"
unique="true"
/>

<many-to-one
name="address"
class="..Address"
cascade="all"
outer-join="auto"
update="true"
insert="true"
foreign-key="FK_ADDRESS"
column="FK_ADDRESS_ID"
unique="false"
/>

<set
name="settings"
lazy="true"
cascade="all-delete-orphan"
sort="unsorted"
>

<key
column="LOCATION_ID"
>
</key>

<one-to-many
class="..Setting"
/>

</set>

<set
name="contactDetails"
lazy="true"
cascade="all"
sort="unsorted"
>

<key
column="LOCATION_ID"
>
</key>

<one-to-many
class="..ContactDetails"
/>

</set>

<set
name="products"
table="..PRODUCT_LOCATION"
lazy="false"
cascade="all"
sort="unsorted"
>

<key
column="FK_LOCATION_ID"
>
</key>

<many-to-many
class="..Product"
column="FK_PRODUCT_ID"
outer-join="auto"
/>

</set>

<subclass
name="..School"
discriminator-value="school"
>
<property
name="enterpriseID"
type="string"
update="true"
insert="true"
column="ENTERPRISE_ID"
length="32"
unique="false"
/>

<property
name="schoolID"
type="string"
update="true"
insert="true"
column="SCHOOL_ID"
length="60"
unique="false"
/>

<many-to-one
name="district"
class="..District"
cascade="save-update"
outer-join="auto"
update="true"
insert="true"
foreign-key="FK_DISTRICT"
column="FK_DISTRICT_ID"
unique="false"
/>

</subclass>

<subclass
name="..District"
discriminator-value="district"
>

<set
name="schools"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
>

<key
column="FK_DISTRICT_ID"
>
</key>

<one-to-many
class="..School"
/>

</set>

</subclass>

<subclass
name="..Home"
discriminator-value="home"
>

</subclass>

</class>

<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>
<query name="findSchoolsByDistrictName"><![CDATA[
from School school left join fetch school.address left join fetch school.settings where school.district.name = ?
]]></query>
<query name="findSchoolByEnterpriseId"><![CDATA[
from School school left join fetch school.address where school.enterpriseID = ?
]]></query>
<query name="findSchoolsByDistrictReportQuery"><![CDATA[
select new School(school.id, school.name, school.schoolID, school.enterpriseID) from School school where school.district = ? order by school.name
]]></query>
<query name="findSchoolsByDistrict"><![CDATA[
from School school left join fetch school.address left join fetch school.settings where school.district = ?
]]></query>
<query name="findSchoolsForUser"><![CDATA[
select distinct school from School school, User user where user = ? and school in elements(user.locations)
]]></query>
<query name="findSchoolForLessonPlan"><![CDATA[
select distinct school from School school, LessonPlan plan where plan = ? and school in elements(plan.sharedLocations)
]]></query>
<query name="findSchoolForActivity"><![CDATA[
select distinct school from School school, Activity activity where activity = ? and school in elements(activity.sharedLocations)
]]></query>
<query name="findSchoolForTest"><![CDATA[
select distinct school from School school, Test test where test = ? and school in elements(test.sharedLocations)
]]></query>
<query name="findSchoolByName"><![CDATA[
from School school where lower(school.name)= lower(?)
]]></query>
<query name="findSchoolBySchoolID"><![CDATA[
from School school where school.schoolID= ?
]]></query>
<query name="findDistrictForUser"><![CDATA[
select distinct district from District district, User user, School school join user.locations as location where user = ? and school = location and school.district = district
]]></query>
<query name="findDistrictForDistrictAdmin"><![CDATA[
select distinct district from District district, User user join user.locations as location where user = ? and user.userType = ? and district = location
]]></query>
<query name="findDistrictByName"><![CDATA[
select distinct district from District district where district.name = ?
]]></query>
<query name="findDistrictForSchool"><![CDATA[
select distinct district from District district join district.schools as school where school = ?
]]></query>
<query name="findDistrictForLessonPlan"><![CDATA[
select distinct district from District district, LessonPlan lessonPlan join lessonPlan.sharedLocations as location where lessonPlan = ? and district = location
]]></query>
<query name="findDistrictForActivity"><![CDATA[
select distinct district from District district, Activity activity join activity.sharedLocations as location where activity = ? and district = location
]]></query>
<query name="findDistrictForTest"><![CDATA[
select distinct district from District district, Test test join test.sharedLocations as location where test = ? and district = location
]]></query>

</hibernate-mapping>


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.