[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2501) Read-only state of an entity in a session to propagate into subsequently lazy-loaded entities.

Shawn Clowater (JIRA) noreply at atlassian.com
Tue Jul 22 18:58:12 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30711 ] 

Shawn Clowater commented on HHH-2501:
-------------------------------------

Added a rough pass at a patch based on the 3.2.6 code base as it's what I'm currently running.  If the feedback is positive (or negative with suggested improvements) I can look at tweaking it for 3.3.

I only found 2 places where I think I had to check for the attribute, in the TwoPhaseLoad and the DefaultLoadEventListener.  In looking at the DefaultLoadEventListener I think the deep copy could probably be skipped if the session was in a read-only mode.

The one thing I struggled with was how to get explicit updates to entities that were existed in the session as Read-Only.  In my testing I resorted to a manual evict/update process and that seemed to work.  Alternatively I found that you could call setReadOnly(Object, boolean) on the session to return it to a MANAGED status but you had to do that before you changed the property on your entity otherwise it was overwriting the changed value.

I still think it would be handy to have the read only cascade since I had originally been playing with a read only attribute on the Criteria API but it had the effect of loading the root entity as read only and then anything loaded off a many to one ended up being managed.

> Read-only state of an entity in a session to propagate into subsequently lazy-loaded entities.
> ----------------------------------------------------------------------------------------------
>
>                 Key: HHH-2501
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2501
>             Project: Hibernate3
>          Issue Type: New Feature
>          Components: core
>         Environment: any
>            Reporter: Gunther Schadow
>            Priority: Minor
>         Attachments: HHH-2501.patch
>
>
> ISSUE:
> Given an Entity entity and after Session.setReadOnly(entity), if the entity has lazy collections, lazy properties etc., other Entities are loaded into the Session upon navigating the object graph in the default read-writable state. However, it seems more reasonable to maintain the read-only state of the owning object.
> REQUEST:
> Ability to propagate read-only state of an entity in a session into other lazy-loaded entities.
> BACKGROUND:
> We have a system which permits users to make concurrent transactions which involve many of the same objects. Usually no changes happen on these shared objects, but instead connections (links) are made between these objects and new objects. For example, say you have an online meeting system, and every Meeting held has a link to a number of User object. The User objects are never changed in a Meeting, but there is a Relation called Participation (of User in Meeting) to which new relationships are added. When a new meeting is saved, it wants to save the  User objects simply because a new Participation link entry was added to the collection.
> To an extent we can prevent this from happening by setting the Users explicitly to read-only. However, now suppose we added a function "Invite your Friends" to a Meeting, in which we would simply go:
> for(User friend : currentUser.getFriends())
>    meeting.addInvitation(friend);
> Now an Invitation is like a Participation, and would be added into the User but now it wants to save these users just for a version upgrade only because they have received an Invitation.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list