HHH-4704 - Pass session into EntityTuplizer#setIdentifier

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18736 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-02-08 21:28:05 +00:00
parent 839e23458a
commit 8b12e759f0
4 changed files with 84 additions and 24 deletions

View File

@ -1,10 +1,13 @@
package org.hibernate.test.annotations.derivedidentities.e1.a;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.ManyToOne;
import org.hibernate.annotations.Cascade;
/**
* @author Emmanuel Bernard
@ -12,13 +15,9 @@ import javax.persistence.ManyToOne;
@Entity
@IdClass(DependentId.class)
public class Dependent {
@Id
String name;
private String name;
// id attribute mapped by join column default
@Id
@ManyToOne
Employee emp;
private Employee emp;
public Dependent() {
}
@ -27,4 +26,24 @@ public class Dependent {
this.name = name;
this.emp = emp;
}
@Id
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Id
@ManyToOne( cascade = CascadeType.PERSIST )
@Cascade( org.hibernate.annotations.CascadeType.SAVE_UPDATE )
public Employee getEmp() {
return emp;
}
public void setEmp(Employee emp) {
this.emp = emp;
}
}

View File

@ -16,4 +16,20 @@ public class DependentId implements Serializable {
this.name = name;
this.emp = emp;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getEmp() {
return emp;
}
public void setEmp(long emp) {
this.emp = emp;
}
}

View File

@ -1,15 +1,13 @@
package org.hibernate.test.annotations.derivedidentities.e1.a;
import org.hibernate.Session;
import org.hibernate.junit.FailureExpected;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.test.util.SchemaUtil;
/**
* @author Emmanuel Bernard
*/
public class
DerivedIdentitySimpleParentIdClassDepTest extends TestCase {
public class DerivedIdentitySimpleParentIdClassDepTest extends TestCase {
public void testManyToOne() throws Exception {
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", getCfg() ) );
@ -17,28 +15,22 @@ public class
Session s = openSession();
s.getTransaction().begin();
Employee e = new Employee();
e.empId = 1;
e.empName = "Emmanuel";
e.nickname = "Manu";
s.persist( e );
Dependent d = new Dependent();
d.emp = e;
d.name = "Doggy";
d.emp = e;
Employee e = new Employee( 1L, "Emmanuel", "Manu" );
Dependent d = new Dependent( "Doggy", e );
s.persist( d );
s.persist( e );
s.getTransaction().commit();
s.close();
s = openSession();
s.getTransaction().begin();
DependentId dId = new DependentId( d.name, d.emp.empId );
DependentId dId = new DependentId( d.getName(), d.getEmp().empId );
d = (Dependent) s.get( Dependent.class, dId );
assertEquals( e.empId, d.emp.empId );
assertEquals( e.empName, d.emp.empName );
assertEquals( e.nickname, d.emp.nickname );
assertEquals( e.empId, d.getEmp().empId );
assertEquals( e.empName, d.getEmp().empName );
assertEquals( e.nickname, d.getEmp().nickname );
s.delete( d );
s.delete( d.emp );
s.delete( d.getEmp() );
s.getTransaction().commit();
s.close();
}

View File

@ -8,9 +8,42 @@ import javax.persistence.Id;
*/
@Entity
public class Employee {
@Id
long empId;
String empName;
String nickname;
public Employee() {
}
public Employee(long empId, String empName, String nickname) {
this.empId = empId;
this.empName = empName;
this.nickname = nickname;
}
@Id
public long getEmpId() {
return empId;
}
public void setEmpId(long empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
}