Hibernate version: current cvs version
Mapping documents:
ClassA
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<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>
ClassB
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<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>
Code between sessionFactory.openSession() and session.close():Code:
Session s = super.createSession(new OtOInterceptor());
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();
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();
Full stack trace of any exception that occurs:no exception ...
Name and version of the database you are using:IBM DB2/AS400
The generated SQL (show_sql=true):please look at log-excerpt
Debug level Hibernate log excerpt:Code:
1688 [main] DEBUG net.sf.hibernate.transaction.JDBCTransaction - begin
1688 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
1688 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - using pooled JDBC connection, pool size: 0
1688 [main] DEBUG net.sf.hibernate.transaction.JDBCTransaction - current autocommit status:false
1688 [main] DEBUG net.sf.hibernate.impl.SessionImpl - loading [ClassA#1]
1688 [main] DEBUG net.sf.hibernate.impl.SessionImpl - attempting to resolve [ClassA#1]
1704 [main] DEBUG net.sf.hibernate.impl.SessionImpl - object not resolved in any cache [ClassA#1]
1704 [main] DEBUG net.sf.hibernate.persister.EntityPersister - Materializing entity: [ClassA#1]
1704 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
1704 [main] DEBUG net.sf.hibernate.SQL - select classa0_.id as id1_, classa0_.dummy as dummy1_, classb1_.id as id0_, classb1_.dummy as dummy0_ from DRKTEST.testClassA classa0_ left outer join DRKTEST.testClassB classb1_ on classa0_.id=classb1_.id where classa0_.id=?
1704 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
1782 [main] DEBUG net.sf.hibernate.type.IntegerType - binding '1' to parameter: 1
1891 [main] DEBUG net.sf.hibernate.loader.Loader - processing result set
1891 [main] DEBUG net.sf.hibernate.type.IntegerType - returning '1' as column: id0_
1891 [main] DEBUG net.sf.hibernate.loader.Loader - result row: 1, 1
1891 [main] DEBUG net.sf.hibernate.loader.Loader - Initializing object from ResultSet: 1
1891 [main] DEBUG net.sf.hibernate.loader.Loader - Hydrating entity: ClassB#1
1891 [main] DEBUG net.sf.hibernate.type.StringType - returning 'classB - dummy' as column: dummy0_
1907 [main] DEBUG net.sf.hibernate.loader.Loader - Initializing object from ResultSet: 1
1907 [main] DEBUG net.sf.hibernate.loader.Loader - Hydrating entity: ClassA#1
1907 [main] DEBUG net.sf.hibernate.type.StringType - returning 'classA - dummy' as column: dummy1_
1907 [main] DEBUG net.sf.hibernate.loader.Loader - done processing result set (1 rows)
1907 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
1907 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - closing statement
1922 [main] DEBUG net.sf.hibernate.loader.Loader - total objects hydrated: 2
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - resolving associations for [ClassB#1]
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - loading [ClassA#1]
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - attempting to resolve [ClassA#1]
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - resolved object in session cache [ClassA#1]
loading: ClassB@1e4853f
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - done materializing entity [ClassB#1]
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - resolving associations for [ClassA#1]
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - loading [ClassB#1]
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - attempting to resolve [ClassB#1]
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - resolved object in session cache [ClassB#1]
loading: ClassA@2bd3a
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - done materializing entity [ClassA#1]
1922 [main] DEBUG net.sf.hibernate.impl.SessionImpl - initializing non-lazy collections
--------[classA has classB?]--->true
--------[classB has classA?]--->true
1938 [main] DEBUG net.sf.hibernate.impl.SessionImpl - saveOrUpdate() persistent instance
1938 [main] DEBUG net.sf.hibernate.transaction.JDBCTransaction - commit
1938 [main] DEBUG net.sf.hibernate.impl.SessionImpl - flushing session
1938 [main] DEBUG net.sf.hibernate.engine.Cascades - processing cascades for: ClassA
1938 [main] DEBUG net.sf.hibernate.engine.Cascades - done processing cascades for: ClassA
1938 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections
-------start[Interceptor: findDirty]--------
finding dirty for ClassB@1e4853f
[0] --- ClassB@1e4853f ----[dummy]: currentState=[classB - dummy]: previousState=[classB - dummy]----
[1] --- ClassB@1e4853f ----[classARef]: currentState=[null]: previousState=[ClassA@2bd3a]----
-------end[Interceptor: findDirty]--------
-------start[Interceptor: findDirty]--------
finding dirty for ClassA@2bd3a
[0] --- ClassA@2bd3a ----[dummy]: currentState=[classA - dummy]: previousState=[classA - dummy]----
[1] --- ClassA@2bd3a ----[classBRef]: currentState=[null]: previousState=[ClassB@1e4853f]----
-------end[Interceptor: findDirty]--------
1938 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections
1938 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates
1938 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 insertions, 0 updates, 0 deletions to 2 objects
1938 [main] DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
1938 [main] DEBUG net.sf.hibernate.impl.Printer - listing entities:
1938 [main] DEBUG net.sf.hibernate.impl.Printer - ClassB{classARef=null, dummy=classB - dummy, idClassB=1}
1938 [main] DEBUG net.sf.hibernate.impl.Printer - ClassA{idClassA=1, dummy=classA - dummy, classBRef=null}
1938 [main] DEBUG net.sf.hibernate.impl.SessionImpl - executing flush
1938 [main] DEBUG net.sf.hibernate.impl.SessionImpl - post flush
1954 [main] DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion
1954 [main] DEBUG net.sf.hibernate.impl.SessionImpl - loading [ClassA#1]
1954 [main] DEBUG net.sf.hibernate.impl.SessionImpl - attempting to resolve [ClassA#1]
1954 [main] DEBUG net.sf.hibernate.impl.SessionImpl - resolved object in session cache [ClassA#1]
--------[classA has classB?]--->false
--------[classB has classA?]--->false
1954 [main] DEBUG net.sf.hibernate.impl.SessionImpl - closing session
1954 [main] DEBUG net.sf.hibernate.impl.SessionImpl - disconnecting session
1954 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
1954 [main] DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion
hi,
it seems to me, that there's a bug in handling the one-to-one relationship.
I've two classes with a simple one-to-one relationship and an Interceptor (only tracings, no changes).
Loading ClassA works perfectly and performing some changings will work perfectly, too.
The only thing that doesn't work as i thought it should work is setting the references on the 'foreign-side' to 'null'.
After calling 'saveOrUpdate' and 'commit' the references are 'null' as well as the 'currentstate' in the interceptor ... so everything looks fine for me ... but no delete-statement is executed ...
The first-level-session-cache is now in another state than the database ....
(as you can see in the log, after reloading classA from the session no reference to ClassB is available ...)
What am i doing wrong? Or is it a bug?
TIA
curio