HHH-4529 add test for one to one and embedded id

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18591 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-01-20 18:42:49 +00:00
parent 01720257b2
commit f2e8773d35
2 changed files with 49 additions and 2 deletions

View File

@ -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
};
}
}

View File

@ -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;
}