Author: steve.ebersole(a)jboss.com
Date: 2007-01-22 13:59:20 -0500 (Mon, 22 Jan 2007)
New Revision: 11075
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Address.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Entity.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/OptionalOneToOneTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Org.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Person.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Person.java
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/OneToOneSuite.java
Log:
added tests dealing with optional one-to-one mappings
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/OneToOneSuite.java
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/OneToOneSuite.java 2007-01-22
18:59:05 UTC (rev 11074)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/OneToOneSuite.java 2007-01-22
18:59:20 UTC (rev 11075)
@@ -8,6 +8,7 @@
import org.hibernate.test.onetoone.link.OneToOneLinkTest;
import org.hibernate.test.onetoone.nopojo.DynamicMapOneToOneTest;
import org.hibernate.test.onetoone.singletable.DiscrimSubclassOneToOneTest;
+import org.hibernate.test.onetoone.optional.OptionalOneToOneTest;
/**
* {@inheritDoc}
@@ -21,6 +22,7 @@
suite.addTest( JoinedSubclassOneToOneTest.suite() );
suite.addTest( OneToOneLinkTest.suite() );
suite.addTest( DynamicMapOneToOneTest.suite() );
+ suite.addTest( OptionalOneToOneTest.suite() );
suite.addTest( DiscrimSubclassOneToOneTest.suite() );
return suite;
}
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Address.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Address.java
(rev 0)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Address.java 2007-01-22
18:59:20 UTC (rev 11075)
@@ -0,0 +1,15 @@
+package org.hibernate.test.onetoone.optional;
+
+/**
+ * @author Gavin King
+ */
+public class Address {
+ public String entityName;
+ public String street;
+ public String state;
+ public String zip;
+
+ public String toString() {
+ return this.getClass() + ":" + street;
+ }
+}
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Entity.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Entity.java
(rev 0)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Entity.java 2007-01-22
18:59:20 UTC (rev 11075)
@@ -0,0 +1,8 @@
+package org.hibernate.test.onetoone.optional;
+
+/**
+ * @author Gavin King
+ */
+public class Entity {
+ public String name;
+}
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/OptionalOneToOneTest.java
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/OptionalOneToOneTest.java
(rev 0)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/OptionalOneToOneTest.java 2007-01-22
18:59:20 UTC (rev 11075)
@@ -0,0 +1,50 @@
+package org.hibernate.test.onetoone.optional;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.Session;
+
+/**
+ * @author Gavin King
+ */
+public class OptionalOneToOneTest extends FunctionalTestCase {
+
+ public OptionalOneToOneTest(String str) {
+ super(str);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "onetoone/optional/Person.hbm.xml" };
+ }
+
+ public void configure(Configuration cfg) {
+ cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false");
+ cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( OptionalOneToOneTest.class );
+ }
+
+ public void testOptionalOneToOneRetrieval() {
+ Session s = openSession();
+ s.beginTransaction();
+ Person me = new Person();
+ me.name = "Steve";
+ s.save( me );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ me = ( Person ) s.load( Person.class, me.name );
+ assertNull( me.address );
+ s.delete( me );
+ s.getTransaction().commit();
+ s.close();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Org.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Org.java
(rev 0)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Org.java 2007-01-22
18:59:20 UTC (rev 11075)
@@ -0,0 +1,8 @@
+package org.hibernate.test.onetoone.optional;
+
+
+/**
+ * @author Gavin King
+ */
+public class Org extends Entity {
+}
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Person.hbm.xml
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Person.hbm.xml
(rev 0)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Person.hbm.xml 2007-01-22
18:59:20 UTC (rev 11075)
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ Demonstrates mapping an "optional" one-to-one association. Basically
+ a (zero or one)-to-one.
+
+ Note that this is only conceptually possible on the non-constrained
+ side of the association (the side without the FK).
+
+ Also, it is impossible that the optional side be lazy; we must hit the
+ target table to determine whether a matching row actually exists or not.
+ This is so we can properly determine whether to use null or some value
+ for the association property's value.
+-->
+<hibernate-mapping package="org.hibernate.test.onetoone.optional"
default-access="field">
+
+ <class name="Entity">
+ <id name="name"/>
+ <joined-subclass name="Person">
+ <key column="entityName"/>
+ <one-to-one name="address" cascade="all"
constrained="false" outer-join="false" lazy="proxy"/>
+ </joined-subclass>
+ <joined-subclass name="Org">
+ <key column="entityName"/>
+ </joined-subclass>
+ </class>
+
+ <class name="Address">
+ <id name="entityName"/>
+ <property name="street"/>
+ <property name="state"/>
+ <property name="zip"/>
+ </class>
+
+</hibernate-mapping>
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Person.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Person.java
(rev 0)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/onetoone/optional/Person.java 2007-01-22
18:59:20 UTC (rev 11075)
@@ -0,0 +1,9 @@
+package org.hibernate.test.onetoone.optional;
+
+/**
+ * @author Gavin King
+ */
+public class Person extends Entity {
+ public Address address;
+ public Address mailingAddress;
+}