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