HHH-4529 add tests for parent class @EmbeddedId and derived class @EmbeddedId
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18626 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
5ee9ba361c
commit
eef482fb15
|
@ -0,0 +1,31 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.e3.b;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MapsId;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
public class Dependent {
|
||||
// default column name for "name" attribute is overridden
|
||||
@AttributeOverride(name = "name", column = @Column(name = "dep_name"))
|
||||
@EmbeddedId
|
||||
DependentId id;
|
||||
|
||||
|
||||
@MapsId("empPK")
|
||||
@JoinColumns({
|
||||
@JoinColumn(name = "FK1", referencedColumnName = "firstName"),
|
||||
@JoinColumn(name = "FK2", referencedColumnName = "lastName")
|
||||
})
|
||||
@ManyToOne
|
||||
Employee emp;
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.e3.b;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Embeddable
|
||||
public class DependentId implements Serializable {
|
||||
String name;
|
||||
EmployeeId empPK;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.e3.b;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.test.annotations.TestCase;
|
||||
import org.hibernate.test.util.SchemaUtil;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class DerivedIdentityEmbeddedIdParentEmbeddedIdDepTest extends TestCase {
|
||||
public void testManyToOne() throws Exception {
|
||||
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK1", getCfg() ) );
|
||||
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK2", getCfg() ) );
|
||||
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "dep_name", getCfg() ) );
|
||||
assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "firstName", getCfg() ) );
|
||||
assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "lastName", getCfg() ) );
|
||||
Employee e = new Employee();
|
||||
e.empId = new EmployeeId();
|
||||
e.empId.firstName = "Emmanuel";
|
||||
e.empId.lastName = "Bernard";
|
||||
Session s = openSession( );
|
||||
s.getTransaction().begin();
|
||||
s.persist( e );
|
||||
Dependent d = new Dependent();
|
||||
d.emp = e;
|
||||
d.id = new DependentId();
|
||||
d.id.name = "Doggy";
|
||||
d.id.empPK = new EmployeeId();
|
||||
d.id.empPK.firstName = e.empId.firstName; //FIXME not needed when foreign is enabled
|
||||
d.id.empPK.lastName = e.empId.lastName; //FIXME not needed when foreign is enabled
|
||||
s.persist( d );
|
||||
s.flush();
|
||||
s.clear();
|
||||
d = (Dependent) s.get( Dependent.class, d.id );
|
||||
assertNotNull( d.emp );
|
||||
assertEquals( e.empId.firstName, d.emp.empId.firstName );
|
||||
s.getTransaction().rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Dependent.class,
|
||||
Employee.class
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.e3.b;
|
||||
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Entity
|
||||
public class Employee {
|
||||
@EmbeddedId
|
||||
EmployeeId empId;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package org.hibernate.test.annotations.derivedidentities.e3.b;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@Embeddable
|
||||
public class EmployeeId implements Serializable {
|
||||
String firstName;
|
||||
String lastName;
|
||||
}
|
Loading…
Reference in New Issue