-->
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: caching collection of read-only objects
PostPosted: Wed Jun 22, 2005 12:15 pm 
Newbie

Joined: Wed Apr 27, 2005 5:32 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0
Mapping documents:
membership.hbm.xml:

<?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="myapp.Membership" table="MEMBERSHIP">
<cache usage="nonstrict-read-write"/>
<id name="id" type="long">
<column name="PK_MEMBERSHIP_ID" not-null="true"/>
<generator class="increment"/>
</id>
<property name="regionId" type="long">
<column name="FK_REGION_ID"/>
</property>
<property name="membershipName" type="string">
<column name="MEMBERSHIP_NAME"/>
</property>

<set name="members" cascade="save-update" table="MEMBERSHIP_PLAYER_MAP" lazy="false">
<cache usage="nonstrict-read-write"/>
<key column="MEMBERSHIP_ID"/>
<many-to-many class="myapp.Member" column="MEMBER_ID"/>
</set>

</class>
</hibernate-mapping>


member.hbm.xml

<?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="myapp.Member" table="MEMBERS">
<cache usage="read-only"/>
<id name="id" type="long" unsaved-value="0">
<column name="PK_MEMBER_ID"/>
<generator class="increment"/>
</id>
<property name="name" column="MEMBER_NAME" type="string" not-null="false"/>
<property name="code" column="MEMBER_CODE" type="string" not-null="false"/>
<property name="category" column="CATEGORY" type="string" not-null="false"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
not sure - all done by Spring, HibernateTemplate
Full stack trace of any exception that occurs:
When I set in member.hbm.xml "<cache usage="nonstrict-read-write"/>":

START :: MembershipDAOHibernate:saveMembership(...)
CoherenceCacheProvider:nextTimestamp()
Membership:getMembers()
Membership:getMembers()
Membership:setMembers()
Membership:getMembers()
Membership:getMembers()
Membership:getMembers()
Hibernate: insert into MEMBERSHIP (FK_REGION_ID, MEMBERSHIP_NAME, PK_MEMBERSHIP_ID) values (?, ?, ?)
Hibernate: update MEMBERS set MEMBER_NAME=?, AVAILABILITY=?, MEMBER_CODE=?, CATEGORY=? where PK_MEMBER_ID=?
CoherenceCache:remove(Object key), key = myapp.Member#15579
Hibernate: update MEMBERS set MEMBER_NAME=?, AVAILABILITY=?, MEMBER_CODE=?, CATEGORY=? where PK_MEMBER_ID=?
CoherenceCache:remove(Object key), key = myapp.Member#15381
Hibernate: update MEMBERS set MEMBER_NAME=?, AVAILABILITY=?, MEMBER_CODE=?, CATEGORY=? where PK_MEMBER_ID=?
CoherenceCache:remove(Object key), key = myapp.Member#15459
Hibernate: update MEMBERS set MEMBER_NAME=?, AVAILABILITY=?, MEMBER_CODE=?, CATEGORY=? where PK_MEMBER_ID=?
CoherenceCache:remove(Object key), key = myapp.Member#15689
Hibernate: insert into MEMBERSHIP_MEMBER_MAP (MEMBERSHIP_ID, MEMBER_ID) values (?, ?)
Hibernate: insert into MEMBERSHIP_MEMBER_MAP (MEMBERSHIP_ID, MEMBER_ID) values (?, ?)
Hibernate: insert into MEMBERSHIP_MEMBER_MAP (MEMBERSHIP_ID, MEMBER_ID) values (?, ?)
Hibernate: insert into MEMBERSHIP_MEMBER_MAP (MEMBERSHIP_ID, MEMBER_ID) values (?, ?)
CoherenceCache:remove(Object key), key = myapp.Membership.players#11111291
CoherenceCache:remove(Object key), key = myapp.Member#15579
CoherenceCache:remove(Object key), key = myapp.Member#15381
CoherenceCache:remove(Object key), key = myapp.Member#15459
CoherenceCache:remove(Object key), key = myapp.Member#15689
CoherenceCache:remove(Object key), key = myapp.Membership.players#11111291
END :: MembershipDAOHibernate:s
Membership:getMembers()



==========================================

...and when I set in member.hbm.xml "<cache usage="nonstrict-read-write"/>":

START :: MembershipDAOHibernate:saveMembership(...)
CoherenceCacheProvider:nextTimestamp()
Membership:getMembers()
Membership:getMembers()
Membership:setMembers()
Membership:getMembers()
Membership:getMembers()
Membership:getMembers()
Hibernate: insert into MEMBERSHIP (FK_REGION_ID, MEMBERSHIP_NAME, PK_MEMBERSHIP_ID) values (?, ?, ?)
22-Jun-2005 15:30:58 org.hibernate.cache.ReadOnlyCache lock
SEVERE: Application attempted to edit read only item: myapp.Member#15582
22-Jun-2005 15:30:58 org.hibernate.cache.ReadOnlyCache release
SEVERE: Application attempted to edit read only item: myapp.Member#15582
Can't write to a readonly object
Name and version of the database you are using:
Oracle 10g
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I would like Member objects to be read-only. Nut when I set cache to "read-only" I get this error:
------------------------------------------------------------------------------------
22-Jun-2005 15:30:58 org.hibernate.cache.ReadOnlyCache lock
SEVERE: Application attempted to edit read only item: myapp.Member#15582
22-Jun-2005 15:30:58 org.hibernate.cache.ReadOnlyCache release
SEVERE: Application attempted to edit read only item: myapp.Member#15582
Can't write to a readonly object
-----------------------------------------------------------------------------------

Exception is thrown when I create Membership object and assign existing pre-cached members to it (set of members). However, when I set cache of Member class to nonstrict-read-write it works fine. I need to have Member object read-only.
where did I go wrong?

Any help is greatly appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 4:53 am 
Newbie

Joined: Wed Apr 27, 2005 5:32 am
Posts: 8
Correction:
the second stack trace from top :

...and when I set in member.hbm.xml "<cache usage="nonstrict-read-write"/>":

Must be :
..."<cache usage="read-only"/>":

It seems like hibernate tries to modify Member objects while I expect it to add pre-cached objects to Membership object.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 6:17 am 
Newbie

Joined: Fri Jun 10, 2005 11:25 am
Posts: 18
I assume there is a typo in membership.hbm.xml, line: "<set name="members" cascade="save-update" table="MEMBERSHIP_PLAYER_MAP" lazy="false"> "
and attribute "table" is ment to be called MEMBERSHIP_MEMBER_MAP as your stack trace indicates but not MEMBERSHIP_PLAYER_MAP.

The solution: in membership.hbm.xml:
in element <set>, set attribute cascade="none"


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.