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