-->
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.  [ 1 post ] 
Author Message
 Post subject: detached object cascading changes
PostPosted: Mon Nov 10, 2008 11:06 am 
Newbie

Joined: Thu Feb 08, 2007 7:53 pm
Posts: 5
I'm seeing behavior after calling Session#evict where changes to that object are stll persisted. Here are the details.

Hibernate 3.3.1GA

I have a User class with a set of roles:
Code:
<set name='roles' table='USER_TO_ROLE' cascade='all' lazy='false'>
  <key column='USER_ID'/>
  <composite-element class="Authorization">
    <many-to-one class="Role"
                 name="role"
                 column="ROLE_ID"
                 not-null="true"
     />
  </composite-element>
</set>


In the application at login time, additional roles may be added to this set programmatically if certain other conditions are met. But we do not want these roles to be persisted to the db.

Here's what I'm currently trying that fails:
Code:
fetch user from db
perform login-logic including initialization of references and checks on if other roles need to be programmatically added
call Session#evict(user)
add additional roles


the error i'm getting is
Code:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: <package name>.Role

The reason we're getting this error is because the programmatically-added roles are constants and not ones read up via Hib sessions and lack PKs. And this error is exposing the fact that Hib is trying to do the insert. In fact, when I turn on org.hibernate and org.hibernate.SQL logging to ALL I can see where Hibernate is evicting the User and the Role collection, and then where the 'insert' is still happening.

Any thots on why this may be happening? I can send more detail (log output, etc) if anybody thinks that can be useful.

dlgrasse


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.