diff --git a/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java b/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java index f38d606c83..f2286dba30 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java @@ -9,7 +9,7 @@ import org.hibernate.test.util.SchemaUtil; */ public class DerivedIdentitySimpleParentEmbeddedIdDepTest extends TestCase { - public void testIt() throws Exception { + public void testManyToOne() throws Exception { assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK", getCfg() ) ); assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "empPK", getCfg() ) ); Employee e = new Employee(); @@ -32,11 +32,35 @@ public class DerivedIdentitySimpleParentEmbeddedIdDepTest extends TestCase { s.close(); } + public void testOneToOne() throws Exception { + assertTrue( SchemaUtil.isColumnPresent( "ExclusiveDependent", "FK", getCfg() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "ExclusiveDependent", "empPK", getCfg() ) ); + Employee e = new Employee(); + e.empId = 1; + e.empName = "Emmanuel"; + Session s = openSession( ); + s.getTransaction().begin(); + s.persist( e ); + ExclusiveDependent d = new ExclusiveDependent(); + d.emp = e; + d.id = new DependentId(); + d.id.name = "Doggy"; + d.id.empPK = e.empId; //FIXME not needed when foreign is enabled + s.persist( d ); + s.flush(); + s.clear(); + d = (ExclusiveDependent) s.get( ExclusiveDependent.class, d.id ); + assertEquals( d.id.empPK, d.emp.empId ); + s.getTransaction().rollback(); + s.close(); + } + @Override protected Class[] getMappings() { return new Class[] { Dependent.class, - Employee.class + Employee.class, + ExclusiveDependent.class }; } } diff --git a/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/ExclusiveDependent.java b/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/ExclusiveDependent.java new file mode 100644 index 0000000000..ad01f92f65 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/ExclusiveDependent.java @@ -0,0 +1,23 @@ +package org.hibernate.test.annotations.derivedidentities.e1.b; + +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.MapsId; +import javax.persistence.OneToOne; + +/** + * @author Emmanuel Bernard + */ +@Entity +public class ExclusiveDependent { + @EmbeddedId + DependentId id; + + @JoinColumn(name = "FK") + // id attribute mapped by join column default + @MapsId("empPK") + // maps empPK attribute of embedded id + @OneToOne + Employee emp; +}