HHH-4529 Add support for parent's id as IdClass and derived entity reusing the same PK class than the parent
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18627 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
eef482fb15
commit
9f85525e45
|
@ -2000,9 +2000,9 @@ public final class
|
||||||
+ " must not have @Id properties when used as an @EmbeddedId: "
|
+ " must not have @Id properties when used as an @EmbeddedId: "
|
||||||
+ BinderHelper.getPath( propertyHolder, inferredData ) );
|
+ BinderHelper.getPath( propertyHolder, inferredData ) );
|
||||||
}
|
}
|
||||||
if ( comp.getPropertySpan() == 0 ) {
|
if ( referencedEntityName == null && comp.getPropertySpan() == 0 ) {
|
||||||
throw new AnnotationException( comp.getComponentClassName()
|
throw new AnnotationException( comp.getComponentClassName()
|
||||||
+ " has no persistent id property"
|
+ " has no persistent id property: "
|
||||||
+ BinderHelper.getPath( propertyHolder, inferredData ) );
|
+ BinderHelper.getPath( propertyHolder, inferredData ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.hibernate.test.annotations.derivedidentities.e5.b;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.test.annotations.TestCase;
|
||||||
|
import org.hibernate.test.util.SchemaUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
public class DerivedIdentityIdClassParentSameIdTypeDepTest extends TestCase {
|
||||||
|
|
||||||
|
public void testOneToOneExplicitJoinColumn() throws Exception {
|
||||||
|
assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", getCfg() ) );
|
||||||
|
assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", getCfg() ) );
|
||||||
|
assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", getCfg() ) );
|
||||||
|
Person e = new Person();
|
||||||
|
e.firstName = "Emmanuel";
|
||||||
|
e.lastName = "Bernard";
|
||||||
|
Session s = openSession( );
|
||||||
|
s.getTransaction().begin();
|
||||||
|
s.persist( e );
|
||||||
|
MedicalHistory d = new MedicalHistory();
|
||||||
|
d.id = new PersonId();
|
||||||
|
d.id.firstName = "Emmanuel"; //FIXME not needed when foreign is enabled
|
||||||
|
d.id.lastName = "Bernard"; //FIXME not needed when foreign is enabled
|
||||||
|
d.patient = e;
|
||||||
|
s.persist( d );
|
||||||
|
s.flush();
|
||||||
|
s.clear();
|
||||||
|
d = (MedicalHistory) s.get( MedicalHistory.class, d.id );
|
||||||
|
assertEquals( d.id.firstName, d.patient.firstName );
|
||||||
|
s.getTransaction().rollback();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
|
return new Class<?>[] {
|
||||||
|
MedicalHistory.class,
|
||||||
|
Person.class
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package org.hibernate.test.annotations.derivedidentities.e5.b;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import javax.persistence.EmbeddedId;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.JoinColumns;
|
||||||
|
import javax.persistence.MapsId;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class MedicalHistory {
|
||||||
|
//all attributes map to relationship: AttributeOverride not allowed
|
||||||
|
@EmbeddedId
|
||||||
|
PersonId id;
|
||||||
|
|
||||||
|
@MapsId
|
||||||
|
@JoinColumns({
|
||||||
|
@JoinColumn(name = "FK1", referencedColumnName = "firstName"),
|
||||||
|
@JoinColumn(name = "FK2", referencedColumnName = "lastName")
|
||||||
|
})
|
||||||
|
@OneToOne
|
||||||
|
Person patient;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.hibernate.test.annotations.derivedidentities.e5.b;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.IdClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@IdClass(PersonId.class)
|
||||||
|
public class Person {
|
||||||
|
@Id
|
||||||
|
String firstName;
|
||||||
|
@Id
|
||||||
|
String lastName;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.hibernate.test.annotations.derivedidentities.e5.b;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
public class PersonId implements Serializable {
|
||||||
|
String firstName;
|
||||||
|
String lastName;
|
||||||
|
}
|
Loading…
Reference in New Issue