Index: test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java =================================================================== --- test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java (revision 11639) +++ test/org/hibernate/test/instrument/runtime/AbstractTransformingClassLoaderInstrumentTestCase.java (working copy) @@ -78,8 +78,10 @@ executeExecutable( "org.hibernate.test.instrument.cases.TestLazyPropertyCustomTypeExecutable" ); } + public void testSharedPKOneToOne() { + executeExecutable( "org.hibernate.test.instrument.cases.TestSharedPKOneToOneExecutable" ); + } - // reflection code to ensure isolation into the created classloader ~~~~~~~ private static final Class[] SIG = new Class[] {}; Index: test/org/hibernate/test/instrument/runtime/CGLIBInstrumentationTest.java =================================================================== --- test/org/hibernate/test/instrument/runtime/CGLIBInstrumentationTest.java (revision 11639) +++ test/org/hibernate/test/instrument/runtime/CGLIBInstrumentationTest.java (working copy) @@ -48,4 +48,8 @@ public void testManyToOneProxy() { super.testManyToOneProxy(); //To change body of overridden methods use File | Settings | File Templates. } + + public void testSharedPKOneToOne() { + super.testSharedPKOneToOne(); + } } Index: test/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java =================================================================== --- test/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java (revision 11639) +++ test/org/hibernate/test/instrument/runtime/JavassistInstrumentationTest.java (working copy) @@ -49,4 +49,8 @@ public void testManyToOneProxy() { super.testManyToOneProxy(); } + + public void testSharedPKOneToOne() { + super.testSharedPKOneToOne(); + } } Index: test/org/hibernate/test/instrument/domain/EntityWithOneToOnes.java =================================================================== --- test/org/hibernate/test/instrument/domain/EntityWithOneToOnes.java (revision 0) +++ test/org/hibernate/test/instrument/domain/EntityWithOneToOnes.java (revision 0) @@ -0,0 +1,50 @@ +package org.hibernate.test.instrument.domain; + +/** + * @author Gail Badner + */ +public class EntityWithOneToOnes { + private Long id; + private String name; + private OneToOneNoProxy oneToOneNoProxy; + private OneToOneProxy oneToOneProxy; + + public EntityWithOneToOnes() { + } + + public EntityWithOneToOnes(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public OneToOneNoProxy getOneToOneNoProxy() { + return oneToOneNoProxy; + } + + public void setOneToOneNoProxy(OneToOneNoProxy oneToOneNoProxy) { + this.oneToOneNoProxy = oneToOneNoProxy; + } + + public OneToOneProxy getOneToOneProxy() { + return oneToOneProxy; + } + + public void setOneToOneProxy(OneToOneProxy oneToOneProxy) { + this.oneToOneProxy = oneToOneProxy; + } +} Index: test/org/hibernate/test/instrument/domain/OneToOneNoProxy.java =================================================================== --- test/org/hibernate/test/instrument/domain/OneToOneNoProxy.java (revision 0) +++ test/org/hibernate/test/instrument/domain/OneToOneNoProxy.java (revision 0) @@ -0,0 +1,45 @@ +package org.hibernate.test.instrument.domain; + +/** + * @author Gail Badner + */ +public class OneToOneNoProxy { + private Long entityId; + private String name; + private EntityWithOneToOnes entity; + + public OneToOneNoProxy() {} + public OneToOneNoProxy(String name) { + this.name = name; + } + /** + * @return Returns the id. + */ + public Long getEntityId() { + return entityId; + } + /** + * @param entityId The id to set. + */ + public void setEntityId(Long entityId) { + this.entityId = entityId; + } + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } + public EntityWithOneToOnes getEntity() { + return entity; + } + public void setEntity(EntityWithOneToOnes entity) { + this.entity = entity; + } +} Index: test/org/hibernate/test/instrument/domain/OneToOneProxy.java =================================================================== --- test/org/hibernate/test/instrument/domain/OneToOneProxy.java (revision 0) +++ test/org/hibernate/test/instrument/domain/OneToOneProxy.java (revision 0) @@ -0,0 +1,45 @@ +package org.hibernate.test.instrument.domain; + +/** + * @author Gail Badner + */ +public class OneToOneProxy { + private Long entityId; + private String name; + private EntityWithOneToOnes entity; + + public OneToOneProxy() {} + public OneToOneProxy(String name) { + this.name = name; + } + /** + * @return Returns the id. + */ + public Long getEntityId() { + return entityId; + } + /** + * @param entityId The id to set. + */ + public void setEntityId(Long entityId) { + this.entityId = entityId; + } + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } + public EntityWithOneToOnes getEntity() { + return entity; + } + public void setEntity(EntityWithOneToOnes entity) { + this.entity = entity; + } +} Index: test/org/hibernate/test/instrument/domain/SharedPKOneToOne.hbm.xml =================================================================== --- test/org/hibernate/test/instrument/domain/SharedPKOneToOne.hbm.xml (revision 0) +++ test/org/hibernate/test/instrument/domain/SharedPKOneToOne.hbm.xml (revision 0) @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + entity + + + + + + + + + + entity + + + + + + + + Index: test/org/hibernate/test/instrument/buildtime/InstrumentTest.java =================================================================== --- test/org/hibernate/test/instrument/buildtime/InstrumentTest.java (revision 11639) +++ test/org/hibernate/test/instrument/buildtime/InstrumentTest.java (working copy) @@ -14,6 +14,7 @@ import org.hibernate.test.instrument.cases.TestIsPropertyInitializedExecutable; import org.hibernate.test.instrument.cases.TestLazyPropertyCustomTypeExecutable; import org.hibernate.test.instrument.cases.TestManyToOneProxyExecutable; +import org.hibernate.test.instrument.cases.TestSharedPKOneToOneExecutable; import org.hibernate.test.instrument.cases.Executable; import org.hibernate.junit.UnitTestCase; @@ -62,6 +63,10 @@ execute( new TestLazyPropertyCustomTypeExecutable() ); } + public void testSharedPKOneToOne() { + execute( new TestSharedPKOneToOneExecutable() ); + } + private void execute(Executable executable) { executable.prepare(); try { Index: test/org/hibernate/test/instrument/cases/TestSharedPKOneToOneExecutable.java =================================================================== --- test/org/hibernate/test/instrument/cases/TestSharedPKOneToOneExecutable.java (revision 0) +++ test/org/hibernate/test/instrument/cases/TestSharedPKOneToOneExecutable.java (revision 0) @@ -0,0 +1,69 @@ +package org.hibernate.test.instrument.cases; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.Hibernate; +import org.hibernate.test.instrument.domain.EntityWithOneToOnes; +import org.hibernate.test.instrument.domain.OneToOneProxy; +import org.hibernate.test.instrument.domain.OneToOneNoProxy; +import junit.framework.Assert; + +/** + * + * @author Gail Badner + */ +public class TestSharedPKOneToOneExecutable extends AbstractExecutable { + + protected String[] getResources() { + return new String[] {"org/hibernate/test/instrument/domain/SharedPKOneToOne.hbm.xml"}; + } + + public void execute() { + Session s = getFactory().openSession(); + Transaction t = s.beginTransaction(); + EntityWithOneToOnes root = new EntityWithOneToOnes( "root" ); + OneToOneProxy oneToOneProxy = new OneToOneProxy( "oneToOneProxy" ); + root.setOneToOneProxy( oneToOneProxy ); + oneToOneProxy.setEntity( root ); + OneToOneNoProxy oneToOneNoProxy = new OneToOneNoProxy( "oneToOneNoProxy" ); + root.setOneToOneNoProxy( oneToOneNoProxy ); + oneToOneNoProxy.setEntity( root ); + + s.save( root ); + t.commit(); + s.close(); + + // NOTE : oneToOneProxy is mapped with lazy="proxy"; oneToOneNoProxy with lazy="no-proxy"... + + s = getFactory().openSession(); + t = s.beginTransaction(); + // load root + root = ( EntityWithOneToOnes ) s.load( EntityWithOneToOnes.class, root.getId() ); + Assert.assertFalse( Hibernate.isInitialized( root ) ); + Assert.assertFalse( Hibernate.isPropertyInitialized( root, "name" ) ); + Assert.assertFalse( Hibernate.isPropertyInitialized( root, "oneToOneProxy" ) ); + Assert.assertFalse( Hibernate.isPropertyInitialized( root, "oneToOneNoProxy" ) ); + + root.getName(); + Assert.assertTrue( Hibernate.isInitialized( root ) ); + Assert.assertTrue( Hibernate.isPropertyInitialized( root, "name" ) ); + Assert.assertTrue( Hibernate.isPropertyInitialized( root, "oneToOneProxy" ) ); + Assert.assertFalse( Hibernate.isPropertyInitialized( root, "oneToOneNoProxy" ) ); + + // get a handle to the oneToOneProxy proxy reference (and make certain that + // this does not force the lazy properties of the root entity + // to get initialized. + root.getOneToOneProxy(); + Assert.assertTrue( Hibernate.isInitialized( oneToOneProxy ) ); + Assert.assertTrue( Hibernate.isPropertyInitialized( root.getOneToOneProxy(), "name" ) ); + Assert.assertFalse( Hibernate.isPropertyInitialized( root, "oneToOneNoProxy" ) ); + + root.getOneToOneNoProxy(); + Assert.assertTrue( Hibernate.isPropertyInitialized( root, "oneToOneNoProxy" ) ); + Assert.assertTrue( Hibernate.isPropertyInitialized( root.getOneToOneNoProxy(), "name") ); + + s.delete( root ); + t.commit(); + s.close(); + } +}