i think i've got it right ... and found a bug ... but i can be wrong ...
Mapping files:
Code:
<hibernate-mapping>
<class
name="ClassA"
table="testClassA">
<id name="idClassA"
column="id"
type="integer"
unsaved-value="0">
<generator class="increment"/>
</id>
<property
name="dummy"
column="dummy"
type="string"/>
<one-to-one
name="classBRef"
class="ClassB"
outer-join="true"
cascade="all"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class
name="ClassB"
table="testClassB">
<id name="idClassB"
column="id"
type="integer"
unsaved-value="0">
<generator class="foreign">
<param name="property">classARef</param>
</generator>
</id>
<property
name="dummy"
column="dummy"
type="string"/>
<one-to-one
name="classARef"
class="ClassA"
outer-join="true"
constrained="true"/>
</class>
</hibernate-mapping>
Two Classes with a one-to-one-Relationship ...
The code i use (quick and dirty):
Code:
Session s = super.createSession();
Transaction t = s.beginTransaction();
ClassA classA = (ClassA)s.load(ClassA.class, new Integer(1));
boolean aHasB = classA.getClassBRef() != null;
boolean bHasA = classA.getClassBRef().getClassARef() != null;
System.err.println("--------[classA has classB?]--->"+aHasB);
System.err.println("--------[classB has classA?]--->"+bHasA);
// remove classB-Ref
classA.getClassBRef().setClassARef(null);
classA.setClassBRef(null);
s.saveOrUpdate(classA);
t.commit();
// reload classA from first-level-cache!
classA = (ClassA)s.load(ClassA.class, new Integer(1));
aHasB = classA.getClassBRef() != null;
if (aHasB)
bHasA = classA.getClassBRef().getClassARef() != null;
else
bHasA = false;
System.err.println("--------[classA has classB?]--->"+aHasB);
System.err.println("--------[classB has classA?]--->"+bHasA);
s.close();
And the log:
Code:
1828 [main] DEBUG net.sf.hibernate.impl.SessionImpl - initializing non-lazy collections
--------[classA has classB?]--->true
--------[classB has classA?]--->true
1828 [main] DEBUG net.sf.hibernate.impl.SessionImpl - saveOrUpdate() persistent instance
1828 [main] DEBUG net.sf.hibernate.transaction.JDBCTransaction - commit
1828 [main] DEBUG net.sf.hibernate.impl.SessionImpl - flushing session
1828 [main] DEBUG net.sf.hibernate.engine.Cascades - processing cascades for: ClassA
1828 [main] DEBUG net.sf.hibernate.engine.Cascades - done processing cascades for: ClassA
1828 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections
1828 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections
1828 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates
1828 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 insertions, 0 updates, 0 deletions to 2 objects
1828 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
1843 [main] DEBUG net.sf.hibernate.impl.Printer - listing entities:
1843 [main] DEBUG net.sf.hibernate.impl.Printer - ClassB{classARef=null, dummy=testDummyB, idClassB=1}
1843 [main] DEBUG net.sf.hibernate.impl.Printer - ClassA{idClassA=1, dummy=testDummyA, classBRef=null}
1843 [main] DEBUG net.sf.hibernate.impl.SessionImpl - executing flush
1843 [main] DEBUG net.sf.hibernate.impl.SessionImpl - post flush
1843 [main] DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion
1843 [main] DEBUG net.sf.hibernate.impl.SessionImpl - loading [ClassA#1]
1843 [main] DEBUG net.sf.hibernate.impl.SessionImpl - attempting to resolve [ClassA#1]
1843 [main] DEBUG net.sf.hibernate.impl.SessionImpl - resolved object in session cache [ClassA#1]
--------[classA has classB?]--->false
--------[classB has classA?]--->false
1843 [main] DEBUG net.sf.hibernate.impl.SessionImpl - closing session
1843 [main] DEBUG net.sf.hibernate.impl.SessionImpl - disconnecting session
1843 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
1843 [main] DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion
Nothing will be deleted ...
BUT ... like you can se in the log, the reference is deleted at object side, and even in the first-level-cache of the session ...
This can be a bug ... or? What are the hibernate-experts saying?
I'm using the current cvs_snapshot ...
thx!
curio