[hibernate-commits] Hibernate SVN: r10291 - in branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument: cases domain
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Aug 18 17:53:21 EDT 2006
Author: steve.ebersole at jboss.com
Date: 2006-08-18 17:52:34 -0400 (Fri, 18 Aug 2006)
New Revision: 10291
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java
Log:
expanded many-to-one proxy test case
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java 2006-08-18 21:50:41 UTC (rev 10290)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/cases/TestManyToOneProxyExecutable.java 2006-08-18 21:52:34 UTC (rev 10291)
@@ -14,23 +14,53 @@
public void execute() {
Session s = getFactory().openSession();
Transaction t = s.beginTransaction();
- Entity parent = new Entity( "parent" );
- s.save( parent );
- Entity child = new Entity( "child", parent );
- s.save( child );
+ Entity root = new Entity( "root" );
+ Entity child1 = new Entity( "child1" );
+ Entity child2 = new Entity( "child2" );
+ root.setChild( child1 );
+ child1.setSibling( child2 );
+ Entity gChild1 = new Entity( "grandchild 1" );
+ Entity gChild2 = new Entity( "grandchild 2" );
+ child1.setChild( gChild1 );
+ gChild1.setSibling( gChild2 );
+ s.save( root );
t.commit();
s.close();
+ // NOTE : child is mapped with lazy="proxy"; sibling with lazy="no-proxy"...
+
s = getFactory().openSession();
t = s.beginTransaction();
- child = ( Entity ) s.get( Entity.class, child.getId() );
- Assert.assertFalse( Hibernate.isPropertyInitialized( child, "name" ) );
- Assert.assertTrue( Hibernate.isPropertyInitialized( child, "parent" ) );
- parent = child.getParent();
- Assert.assertFalse( Hibernate.isPropertyInitialized( parent, "name" ) );
- Assert.assertFalse( Hibernate.isPropertyInitialized( child, "name" ) );
- s.delete( child );
- s.delete( parent );
+ // load root
+ root = ( Entity ) s.get( Entity.class, root.getId() );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( root, "name" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( root, "sibling" ) );
+ Assert.assertTrue( Hibernate.isPropertyInitialized( root, "child" ) );
+
+ // get a handle to the child1 proxy reference (and make certain that
+ // this does not force the lazy properties of the root entity
+ // to get initialized.
+ child1 = root.getChild();
+ Assert.assertFalse( Hibernate.isInitialized( child1 ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( root, "name" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( root, "sibling" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( child1, "name" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( child1, "sibling" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( child1, "child" ) );
+
+ child1.getName();
+ Assert.assertFalse( Hibernate.isPropertyInitialized( root, "name" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( root, "sibling" ) );
+ Assert.assertTrue( Hibernate.isPropertyInitialized( child1, "name" ) );
+ Assert.assertTrue( Hibernate.isPropertyInitialized( child1, "sibling" ) );
+ Assert.assertTrue( Hibernate.isPropertyInitialized( child1, "child" ) );
+
+ gChild1 = child1.getChild();
+ Assert.assertFalse( Hibernate.isInitialized( gChild1 ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( root, "name" ) );
+ Assert.assertFalse( Hibernate.isPropertyInitialized( root, "sibling" ) );
+
+ s.delete( root );
t.commit();
s.close();
}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml 2006-08-18 21:50:41 UTC (rev 10290)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Documents.hbm.xml 2006-08-18 21:52:34 UTC (rev 10291)
@@ -67,7 +67,8 @@
<generator class="increment"/>
</id>
<property name="name" column="NAME" type="string" lazy="true"/>
- <many-to-one name="parent" column="PRNT_ID" class="Entity" lazy="proxy"/>
+ <many-to-one name="child" column="PRNT_ID" class="Entity" lazy="proxy" cascade="all" />
+ <many-to-one name="sibling" column="RIGHT_ID" class="Entity" lazy="no-proxy" cascade="all" />
</class>
</hibernate-mapping>
\ No newline at end of file
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java 2006-08-18 21:50:41 UTC (rev 10290)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/instrument/domain/Entity.java 2006-08-18 21:52:34 UTC (rev 10291)
@@ -8,7 +8,8 @@
public class Entity {
private Long id;
private String name;
- private Entity parent;
+ private Entity child;
+ private Entity sibling;
public Entity() {
}
@@ -17,15 +18,14 @@
this.name = name;
}
- public Entity(String name, Entity parent) {
- this.name = name;
- this.parent = parent;
- }
-
public Long getId() {
return id;
}
+ public void setId(Long id) {
+ this.id = id;
+ }
+
public String getName() {
return name;
}
@@ -34,11 +34,19 @@
this.name = name;
}
- public Entity getParent() {
- return parent;
+ public Entity getChild() {
+ return child;
}
- public void setParent(Entity parent) {
- this.parent = parent;
+ public void setChild(Entity child) {
+ this.child = child;
}
+
+ public Entity getSibling() {
+ return sibling;
+ }
+
+ public void setSibling(Entity sibling) {
+ this.sibling = sibling;
+ }
}
More information about the hibernate-commits
mailing list