/** * @author Emmanuel Bernard */ @Entity public class Trousers { @Id public Integer id; @OneToOne @JoinColumn(name = "zip_id") public TrousersZip zip; }
/** * @author Emmanuel Bernard */ @Entity public class ExclusiveDependent { @EmbeddedId DependentId id; @JoinColumn(name = "FK", nullable = false) // id attribute mapped by join column default @MapsId("empPK") // maps empPK attribute of embedded id @OneToOne Employee emp; }
/** * @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; }
/** * @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; }
@Entity @Table( name = "DataPoint2" ) public static class DataPoint2 { @Id @GeneratedValue public long id; @OneToOne public DataPoint dp; @OneToOne @org.hibernate.annotations.ForeignKey(name = EXPLICIT_FK_NAME_NATIVE) @JoinColumn(name = "explicit_native") public DataPoint explicit_native; @OneToOne @JoinColumn(name = "explicit_jpa", foreignKey = @javax.persistence.ForeignKey(name = EXPLICIT_FK_NAME_JPA)) public DataPoint explicit_jpa; } }
@javax.persistence.Entity( name = "Parent" ) public static class Parent { @Id @Column(unique = true, nullable = false) private Long id; @OneToOne(optional = false, mappedBy = "parent", cascade = ALL) private Child child; public Long getId() { return id; } public Child getChild() { return child; } public void setChild(Child child) { this.child = child; } }
@Entity public class Preisregelung { @Id private Long id; @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) private Tranchenmodell tranchenmodell; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Tranchenmodell getTranchenmodell() { return tranchenmodell; } public void setTranchenmodell(Tranchenmodell tranchenmodell) { this.tranchenmodell = tranchenmodell; } }
/** * @author Florian Rampp * @author Steve Ebersole */ @Entity @Table( name = "CHILD") public class Child { @Id // A @OneToOne here results in the following DDL: create table child ([...] primary key // (parent), unique (parent)). // Oracle does not like a unique constraint and a PK on the same column (results in ORA-02261) @OneToOne(optional = false) private Parent parent; public void setParent(Parent parent) { this.parent = parent; } }
@javax.persistence.Entity( name = "Child" ) public static class Child { @Id @Column(unique = true, nullable = false) private Long id; @OneToOne(optional = false) @JoinColumn(nullable = false) private Parent parent; public Long getId() { return id; } public Parent getParent() { return parent; } public void setParent(Parent parent) { this.parent = parent; } }