I'm trying to evict objects from the session cache.
I have a Folder and a FolderVersion entity. Both are proxied (lazy=true attribute in the <class> element)
They are linked as a Parent/Child relation:
from Folder mapping...
Code:
<set
name="versions"
table="Folder_Version"
lazy="true"
cascade="all-delete-orphan"
inverse="true">
<key
column="Folder_Id"/>
<one-to-many
class="FolderVersion"/>
</set>
from FolderVersion mapping...
Code:
<many-to-one
name="folder"
class="Folder"
column="Folder_Id"
cascade="save-update"/>
In my application, I load a FolderVersion. // no select, but proxy class created. OK
Then I access it:
Code:
folder = folderVersion.getFolder() // this force a select on the Folder_Version table and no other select (remember both are proxy). OK
Then I access the folder:
Code:
folder.getReference(); // this force a select on the Folder table. OK
Then, I remove it form the session cache
Code:
session.evict( folder )
When the transaction is committed, I hibernate generate this:
Quote:
Hibernate: update Folder set Reference=? where Folder_Id=?
Why?
If I remove the evict() call - or - change the mapping of FolderVersion to :
Code:
<many-to-one
name="folder"
class="Folder"
column="Folder_Id"
cascade="none"/> // cascade now none
The unnecessary update is gone.... But of course I want cascading...
Also, I thougt that after this evict(), if I would do folderVersion.getFolder().getReference(), it would force a select to happen again on the folder table. But it doesn't. Just like if it would have found it in cache......
Hope someone will help me on that one. I'm losing alot of precious time at debugging it.
Thank you,
Here is the Hibernate trace portion when I evict the folder:
DEBUG - evicting entity from memory cache: com.convera.repository.model.Folder@e20ef8
DEBUG - evicting [com.convera.repository.model.Folder]
DEBUG - evicting collection: [com.convera.repository.model.Folder.versions#443]
DEBUG - processing cascades for: com.convera.repository.model.Folder
DEBUG - cascading to collection: com.convera.repository.model.Folder.versions
DEBUG - done processing cascades for: com.convera.repository.model.Folder
And when the transaction is commited:
DEBUG - commit
DEBUG - flushing session
DEBUG - processing cascades for: com.convera.repository.model.ComponentVersion
DEBUG - cascading to collection: com.convera.repository.model.ComponentVersion.parameters
DEBUG - cascading to collection: com.convera.repository.model.ComponentVersion.languages
DEBUG - done processing cascades for: com.convera.repository.model.ComponentVersion
DEBUG - processing cascades for: com.convera.repository.model.FolderVersion
DEBUG - cascading to saveOrUpdate()
DEBUG - id unsaved-value strategy NULL
DEBUG - saveOrUpdate() previously saved instance with id: 443
DEBUG - updating [com.convera.repository.model.Folder#443]
DEBUG - processing cascades for: com.convera.repository.model.Folder
DEBUG - cascading to collection: com.convera.repository.model.Folder.versions
DEBUG - done processing cascades for: com.convera.repository.model.Folder
DEBUG - cascading to saveOrUpdate()
DEBUG - cascading to collection: com.convera.repository.model.FolderVersion.children
DEBUG - cascading to collection: com.convera.repository.model.FolderVersion.names
DEBUG - cascading to saveOrUpdate()
DEBUG - saveOrUpdate() persistent instance
DEBUG - cascading to saveOrUpdate()
DEBUG - saveOrUpdate() persistent instance
DEBUG - done processing cascades for: com.convera.repository.model.FolderVersion
DEBUG - Flushing entities and processing referenced collections
DEBUG - Collection found: [com.convera.repository.model.ComponentVersion.parameters#7], was: [com.convera.repository.model.ComponentVersion.parameters#7]
DEBUG - Collection found: [com.convera.repository.model.ComponentVersion.languages#7], was: [com.convera.repository.model.ComponentVersion.languages#7]
DEBUG - Collection found: [com.convera.repository.model.ComponentVersion.dependencies#7], was: [com.convera.repository.model.ComponentVersion.dependencies#7]
DEBUG - Collection found: [com.convera.repository.model.FolderVersion.children#360], was: [com.convera.repository.model.FolderVersion.children#360]
DEBUG - Collection found: [com.convera.repository.model.FolderVersion.names#360], was: [com.convera.repository.model.FolderVersion.names#360]
DEBUG - Updating entity: [com.convera.repository.model.Folder#443]
DEBUG - Collection found: [com.convera.repository.model.Folder.versions#443], was: [com.convera.repository.model.Folder.versions#443]
DEBUG - Processing unreferenced collections
DEBUG - Scheduling collection removes/(re)creates/updates
DEBUG - Flushed: 0 insertions, 1 updates, 0 deletions to 7 objects
DEBUG - Flushed: 0 (re)creations, 0 updates, 0 removals to 6 collections
DEBUG - listing entities:
DEBUG - com.convera.repository.model.FolderNameVersion{folderVersion=FolderVersion#360, updateCount=0, language=Language#2, name=french, id=296}
DEBUG - com.convera.repository.model.FolderNameVersion{folderVersion=FolderVersion#360, updateCount=0, language=Language#1, name=test, id=290}
DEBUG - com.convera.repository.model.ComponentVersion{component=Component#HRC, dependencies=uninitialized, parameters=uninitialized, description=H&R Classification 1.0, creationDate=01 January 1900 00:00:00, state=VersionState#1, lastUpdatedDate=null, languages=uninitialized, name=1.0, id=7}
DEBUG - com.convera.repository.model.Language{code=en, description=English, id=1}
DEBUG - com.convera.repository.model.FolderVersion{rule=RuleVersion#393, updateCount=2, names=[FolderNameVersion#290, FolderNameVersion#296], componentVersion=ComponentVersion#7, folder=Folder#443, children=uninitialized, parent=null, id=360}
DEBUG - com.convera.repository.model.Language{code=fr, description=French, id=2}
DEBUG - com.convera.repository.model.Folder{versions=uninitialized, id=443, reference=}
DEBUG - executing flush
DEBUG - Updating entity: [com.convera.repository.model.Folder#443]
DEBUG - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG - update Folder set Reference=? where Folder_Id=?
Hibernate: update Folder set Reference=? where Folder_Id=?
DEBUG - preparing statement
DEBUG - Dehydrating entity: [com.convera.repository.model.Folder#443]
DEBUG - binding '' to parameter: 1
DEBUG - binding '443' to parameter: 2
DEBUG - done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG - closing statement
DEBUG - post flush
DEBUG - transaction completion
DEBUG - re-enabling autocommit