I've implemented equals() and hashCode() like this in BVO:
Code:
public boolean equals(Object object) {
if (object == null) {
return false;
}
if (object == this) {
return true;
}
if (!(object instanceof BVO)) {
return false;
}
BVO myObject = (BVO) object;
if (property1 != null && !property1.equals(myObject.property1)) {
return false;
}
// And so on for all properties in BVO.java
// Even for the object refernce and collection containing object ref.
return true;
}
public int hashCode() {
int hash = 17;
hash = 37 * hash + (property1 == null ? 0 : property1.hashCode());
// And so on for all properties in BVO.java
return hash;
}
The object structure looks like this:
Code:
A one-to-many B
Bi-directional, using inverse="true", using jcs cache=read-write, cascade="all" from AVO to BVO, cascade="save-update" from BVO to AVO (many-to-one).
From client I perform this:
1. Delete one BVO from AVO (in Session1)
2. Tries to load the AVO (in Session2)
Here's the log, cannot see that AVO.bVOs gets invalidated???
Code:
DELETING
14:03:13,793 DEBUG HibernateTransactionManager:181 - Opening new session for Hibernate transaction
14:03:13,793 DEBUG SessionFactoryUtils:119 - Opening Hibernate session
14:03:13,793 DEBUG SessionImpl:413 - opened session
14:03:13,793 DEBUG HibernateTransactionManager:70 - Using transaction object [org.springframework.orm.hibernate.HibernateTransactionObject@114b82b]
14:03:13,793 DEBUG HibernateTransactionManager:195 - Beginning Hibernate transaction
14:03:13,793 DEBUG JDBCTransaction:36 - begin
14:03:13,793 DEBUG ThreadObjectManager:76 - Bound value [org.springframework.orm.hibernate.SessionHolder@147358f] for key [net.sf.hibernate.impl.SessionFactoryImpl@81a197] to thread [main]
14:03:13,793 DEBUG ThreadObjectManager:76 - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@d5eb7] for key [org.apache.commons.dbcp.BasicDataSource@149105b] to thread [main]
14:03:13,793 DEBUG BVO:168 - returning parent AVO@7976c1[a_uic=2C90AA1E-00F9-00F9-0001-FFFFF9415565]
14:03:13,793 DEBUG BVO:168 - returning parent AVO@7976c1[a_uic=2C90AA1E-00F9-00F9-0001-FFFFF9415565]
14:03:13,793 DEBUG BVO:328 - before: [BVO@1b01afa[b_uic=2C90AA1E-00F9-00F9-0002-FFFFF9415565,a_uic=AVO@7976c1[a_uic=2C90AA1E-00F9-00F9-0001-FFFFF9415565]]]
14:03:13,793 DEBUG BVO:168 - returning parent AVO@7976c1[a_uic=2C90AA1E-00F9-00F9-0001-FFFFF9415565]
14:03:13,793 DEBUG BVO:168 - returning parent AVO@7976c1[a_uic=2C90AA1E-00F9-00F9-0001-FFFFF9415565]
14:03:13,793 DEBUG BVO:332 - after: []
14:03:13,793 DEBUG XmlBeanFactory:231 - Returning cached instance of singleton bean 'bController'
14:03:13,809 DEBUG ThreadObjectManager:59 - Retrieved value [org.springframework.orm.hibernate.SessionHolder@147358f] for key [net.sf.hibernate.impl.SessionFactoryImpl@81a197] bound to thread [main]
14:03:13,809 DEBUG ThreadObjectManager:59 - Retrieved value [org.springframework.orm.hibernate.SessionHolder@147358f] for key [net.sf.hibernate.impl.SessionFactoryImpl@81a197] bound to thread [main]
14:03:13,809 DEBUG SessionImpl:896 - deleting a transient instance
14:03:13,809 DEBUG BVO:168 - returning parent AVO@7976c1[a_uic=2C90AA1E-00F9-00F9-0001-FFFFF9415565]
14:03:13,809 DEBUG BVO:168 - returning parent AVO@7976c1[a_uic=2C90AA1E-00F9-00F9-0001-FFFFF9415565]
14:03:13,809 DEBUG SessionImpl:941 - deleting [BVO#2C90AA1E-00F9-00F9-0002-FFFFF9415565]
14:03:13,809 DEBUG Cascades:237 - unsaved-value strategy NULL
14:03:13,809 DEBUG Cascades:336 - processing cascades for: BVO
14:03:13,809 DEBUG Cascades:275 - cascading to collection: BVO.cVOs
14:03:13,809 DEBUG Cascades:275 - cascading to collection: BVO.bdVOs
14:03:13,825 DEBUG Cascades:344 - done processing cascades for: BVO
14:03:13,825 DEBUG Cascades:336 - processing cascades for: BVO
14:03:13,825 DEBUG Cascades:344 - done processing cascades for: BVO
14:03:13,825 DEBUG ThreadObjectManager:59 - Retrieved value [org.springframework.orm.hibernate.SessionHolder@147358f] for key [net.sf.hibernate.impl.SessionFactoryImpl@81a197] bound to thread [main]
14:03:13,825 DEBUG HibernateTransactionManager:119 - Triggering beforeCommit synchronization
14:03:13,825 DEBUG HibernateTransactionManager:259 - Flushing Hibernate session on transaction commit
14:03:13,825 DEBUG SessionImpl:2011 - flushing session
14:03:13,825 DEBUG SessionImpl:2113 - Flushing entities and processing referenced collections
14:03:13,825 DEBUG SessionImpl:2397 - Processing unreferenced collections
14:03:13,825 DEBUG SessionImpl:2602 - Collection dereferenced: [BVO.cVOs#2C90AA1E-00F9-00F9-0002-FFFFF9415565]
14:03:13,825 DEBUG SessionImpl:2602 - Collection dereferenced: [BVO.bdVOs#2C90AA1E-00F9-00F9-0002-FFFFF9415565]
14:03:13,825 DEBUG SessionImpl:2408 - Scheduling collection removes/(re)creates/updates
14:03:13,825 DEBUG SessionImpl:2023 - Flushed: 0 insertions, 0 updates, 1 deletions to 1 objects
14:03:13,825 DEBUG SessionImpl:2028 - Flushed: 0 (re)creations, 0 updates, 2 removals to 2 collections
14:03:13,825 DEBUG SessionImpl:2058 - executing flush
14:03:13,825 DEBUG ReadWriteCache:46 - Invalidating: 2C90AA1E-00F9-00F9-0002-FFFFF9415565
14:03:13,840 DEBUG ReadWriteCache:46 - Invalidating: 2C90AA1E-00F9-00F9-0002-FFFFF9415565
14:03:13,840 DEBUG ReadWriteCache:46 - Invalidating: 2C90AA1E-00F9-00F9-0002-FFFFF9415565
14:03:13,840 DEBUG EntityPersister:548 - Deleting entity: BVO#2C90AA1E-00F9-00F9-0002-FFFFF9415565
14:03:13,840 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
14:03:13,840 DEBUG SessionFactoryImpl:526 - prepared statement get: delete from B where b_uic=?
Hibernate: delete from B where b_uic=?
14:03:13,840 DEBUG SessionFactoryImpl:536 - preparing statement
14:03:13,840 DEBUG StringType:44 - binding '2C90AA1E-00F9-00F9-0002-FFFFF9415565' to parameter: 1
14:03:13,840 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
14:03:13,840 DEBUG SessionFactoryImpl:554 - closing statement
14:03:13,840 DEBUG SessionImpl:2428 - post flush
14:03:13,840 DEBUG HibernateTransactionManager:277 - Committing Hibernate transaction
14:03:13,840 DEBUG JDBCTransaction:54 - commit
14:03:13,856 DEBUG SessionImpl:447 - transaction completion
14:03:13,856 DEBUG ReadWriteCache:75 - Releasing: 2C90AA1E-00F9-00F9-0002-FFFFF9415565
14:03:13,856 DEBUG ReadWriteCache:75 - Releasing: 2C90AA1E-00F9-00F9-0002-FFFFF9415565
14:03:13,856 DEBUG ReadWriteCache:75 - Releasing: 2C90AA1E-00F9-00F9-0002-FFFFF9415565
14:03:13,856 DEBUG ThreadObjectManager:92 - Removed value [org.springframework.orm.hibernate.SessionHolder@147358f] for key [net.sf.hibernate.impl.SessionFactoryImpl@81a197] from thread [main]
14:03:13,856 DEBUG ThreadObjectManager:92 - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@d5eb7] for key [org.apache.commons.dbcp.BasicDataSource@149105b] from thread [main]
14:03:13,856 DEBUG HibernateTransactionManager:372 - Closing Hibernate session after transaction
14:03:13,856 DEBUG SessionFactoryUtils:201 - Closing Hibernate session
14:03:13,856 DEBUG SessionImpl:435 - closing session
14:03:13,856 DEBUG SessionImpl:2930 - disconnecting session
14:03:13,856 DEBUG SessionImpl:447 - transaction completion
14:03:13,856 DEBUG HibernateTransactionManager:207 - Triggering afterCompletion synchronization
LOADING
14:03:13,856 DEBUG SessionFactoryUtils:119 - Opening Hibernate session
14:03:13,856 DEBUG SessionImpl:413 - opened session
14:03:13,871 DEBUG SessionImpl:1752 - loading [AVO#2C90AA1E-00F9-00F9-0001-FFFFF9415565]
14:03:13,871 DEBUG SessionImpl:1843 - attempting to resolve [AVO#2C90AA1E-00F9-00F9-0001-FFFFF9415565]
14:03:13,871 DEBUG ReadWriteCache:24 - Cache lookup: 2C90AA1E-00F9-00F9-0001-FFFFF9415565
14:03:13,871 DEBUG ReadWriteCache:33 - Cache hit: 2C90AA1E-00F9-00F9-0001-FFFFF9415565
14:03:13,871 DEBUG SessionImpl:1867 - resolved object in JCS cache [AVO#2C90AA1E-00F9-00F9-0001-FFFFF9415565]
14:03:13,871 DEBUG CollectionPersister:293 - Searching for collection in cache: AVO.bVOs#2C90AA1E-00F9-00F9-0001-FFFFF9415565
14:03:13,871 DEBUG ReadWriteCache:24 - Cache lookup: 2C90AA1E-00F9-00F9-0001-FFFFF9415565
14:03:13,871 DEBUG ReadWriteCache:33 - Cache hit: 2C90AA1E-00F9-00F9-0001-FFFFF9415565
14:03:13,871 DEBUG SessionImpl:1752 - loading [BVO#2C90AA1E-00F9-00F9-0002-FFFFF9415565]
14:03:13,871 DEBUG SessionImpl:1843 - attempting to resolve [BVO#2C90AA1E-00F9-00F9-0002-FFFFF9415565]
14:03:13,871 DEBUG ReadWriteCache:24 - Cache lookup: 2C90AA1E-00F9-00F9-0002-FFFFF9415565
14:03:13,871 DEBUG ReadWriteCache:37 - Cache miss: 2C90AA1E-00F9-00F9-0002-FFFFF9415565
14:03:13,871 DEBUG SessionImpl:1887 - object not resolved in any cache [BVO#2C90AA1E-00F9-00F9-0002-FFFFF9415565]
14:03:13,887 DEBUG EntityPersister:394 - Materializing entity: BVO#2C90AA1E-00F9-00F9-0002-FFFFF9415565
14:03:13,887 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
14:03:13,887 DEBUG SessionFactoryImpl:526 - prepared statement get: select avo1_.a_uic as a_uic0_, bvo0_.b_uic as b_uic1_, bvo0_.a_uic as a_uic1_ from B bvo0_ left outer join A avo1_ on bvo0_.a_uic=avo1_.a_uic where bvo0_.b_uic=?
Hibernate: select avo1_.a_uic as a_uic0_, bvo0_.b_uic as b_uic1_, bvo0_.a_uic as a_uic1_ from B bvo0_ left outer join A avo1_ on bvo0_.a_uic=avo1_.a_uic where bvo0_.b_uic=?
14:03:13,887 DEBUG SessionFactoryImpl:536 - preparing statement
14:03:13,887 DEBUG StringType:44 - binding '2C90AA1E-00F9-00F9-0002-FFFFF9415565' to parameter: 1
14:03:13,903 DEBUG Loader:148 - processing result set
14:03:13,903 DEBUG Loader:182 - done processing result set (0 rows)
14:03:13,903 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
14:03:13,903 DEBUG SessionFactoryImpl:554 - closing statement
14:03:13,903 DEBUG Loader:195 - total objects hydrated: 0
14:03:13,918 DEBUG SessionFactoryUtils:201 - Closing Hibernate session
14:03:13,918 DEBUG SessionImpl:435 - closing session
14:03:13,918 DEBUG SessionImpl:2930 - disconnecting session
14:03:13,918 DEBUG SessionImpl:447 - transaction completion
net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 2C90AA1E-00F9-00F9-0002-FFFFF9415565, of class: BVO
at net.sf.hibernate.impl.SessionImpl.throwObjectNotFound(SessionImpl.java:1678)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1717)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:62)
at net.sf.hibernate.type.EntityType.assemble(EntityType.java:88)
at net.sf.hibernate.collection.Set.<init>(Set.java:94)
at net.sf.hibernate.type.SetType.assembleCachedCollection(SetType.java:36)
at net.sf.hibernate.collection.CollectionPersister.getCachedCollection(CollectionPersister.java:299)
at net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:66)
at net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:177)
at net.sf.hibernate.type.PersistentCollectionType.assemble(PersistentCollectionType.java:129)
at net.sf.hibernate.impl.CacheEntry.assemble(CacheEntry.java:53)
at net.sf.hibernate.impl.CacheEntry.assemble(CacheEntry.java:45)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1872)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688)
at org.springframework.orm.hibernate.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:203)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:144)
at org.springframework.orm.hibernate.HibernateTemplate.load(HibernateTemplate.java:201)
at ADaoImpl.loadByUID(ADaoImpl.java:40)
at AControllerImpl.loadAByUid(AControllerImpl.java:33)
at AServiceImpl.getA(AServiceImpl.java:110)
at ADelegateImpl.loadA(ADelegateImpl.java:51)
at TestClient.loadAByUid(TestClient.java:196)
at TestClient.main(TestClient.java:74)
Exception in thread "main"
Kind regards, Andreas