-->
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.  [ 4 posts ] 
Author Message
 Post subject: session.lock does not reattach
PostPosted: Sun Sep 18, 2005 2:51 pm 
Newbie

Joined: Tue Nov 30, 2004 11:39 am
Posts: 4
Hibernate version: .2.1.7c

Mapping documents:
User
<hibernate-mapping
>
<class
name="org.appfuse.model.User"
table="app_user"
lazy="true"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>

<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="increment">

</generator>
</id>

<many-to-one
name="userEntity"
class="org.appfuse.model.Entity"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="key_entity"
unique="false"
/>

<property
name="userEntityKey"
type="java.lang.Long"
update="false"
insert="false"
access="property"
column="key_entity"
not-null="true"
/>

....

Entity:

<hibernate-mapping
>
<class
name="org.appfuse.model.Entity"
table="tbl_entity"
lazy="true"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>

<id
name="entityKey"
column="key_entity"
type="java.lang.Long"
>
<generator class="increment">

</generator>
</id>

<one-to-one
name="user"
class="org.appfuse.model.User"
cascade="none"
outer-join="auto"
constrained="false"
property-ref="userEntityKey"
/>

<idbag
name="groups"
table="tbl_entity_grp"
lazy="true"
cascade="none"
>
<collection-id
column="id"
type="java.lang.Long"
>
<generator class="increment">
</generator>
</collection-id>

<key
column="key_entity"
>
</key>

<many-to-many
class="org.appfuse.model.EntityGroup"
column="key_group"
outer-join="auto"
/>

</idbag>
....







Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: mysql

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

hi,

I am using hibernate 2.1.7c with spring and struts. I have a User object with a many-to-one relationship with an Entity object. The Entity object has a many-to-many relationship with a EntityGroup object.
The Entity has lazy="true" in its class level attribute. The groups collection of the Entity object also has lazy="true".

I store the User object in an Http Session. For the next web request I retrieve the User object from HttpSession and call session.lock(UserObj, LockMode.NONE).
Using a debugger, I noticed that the User object is associated with the new Hibetnate Session. But the Entity object belonging to the User is still associated with the old Hibernate session.

The code below

Entity e = UserObj.getUserEntity();

List groups = e.getGroups();


is throwing a "Failed to lazily initialize a collection - no session or session was closed" at the line e.getGroups();

It appears that session.lock is associating the User object with the new Hibernate session but is not cascading the lock to the Entity object of the user object.

Is there a way to cascade the locking to the entity object??

Any help is appreciated.

Thanks Nikki


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 1:29 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
AFAIK in 2.1 you have to do the cascading yourself.

In 3.* it seems possible to have Hibernate do it for you (documentation states that you have to specify lock or all as a cascade style for the association) but I didn't try it...

Erik


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 1:19 pm 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
ErikFK wrote:
AFAIK in 2.1 you have to do the cascading yourself.

In 3.* it seems possible to have Hibernate do it for you (documentation states that you have to specify lock or all as a cascade style for the association) but I didn't try it...

Erik

In 2.1 we didn't care about cascading locks, and reattach using lock used to work everywhere, so I'd rather think that cascade="lock" was implicit in 2.1. Now with 3.1 I got some lazy initialization exceptions and I had to add default-cascade="lock" everywhere to fix it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 1:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
more correctly cascading of lock in 2x was implicit in cascading of save-update. That is no longer the case in 3x as lock is now a seperately cascadable event; ex: <many-to-one ... cascade="save-update, lock, delete"/>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.