@OneToOne @JoinColumn(name = "id") @MapsId public Post getPost() { return post; }
@Entity( name = "AdditionalDetails" ) @Table( name = "ADDITIONAL_DETAILS" ) private static class AdditionalDetails { @Id Long id; String details; @OneToOne( optional = false ) @MapsId Post post; } }
@Entity @Table(name="`Policy`") public class Policy { @EmbeddedId PolicyId id; @MapsId("depPK") @ManyToOne Dependent dep; }
@Entity(name = "PersonDetails") public static class PersonDetails { @Id private Long id; private String nickName; @ManyToOne @MapsId private Person person; public String getNickName() { return nickName; } public void setNickName(String nickName) { this.nickName = nickName; } public Person getPerson() { return person; } public void setPerson(Person person) { this.person = person; } } }
@Entity @Table(name="`Dependent`") public class Dependent { @EmbeddedId DependentId id; @MapsId("empPK") @ManyToOne Employee emp; }
/** * @author Emmanuel Bernard */ @Entity public class Dependent { @EmbeddedId DependentId id; //@JoinColumn(name="FK") // id attribute mapped by join column default @MapsId("empPK") // maps empPK attribute of embedded id @ManyToOne @JoinColumn(nullable=false) Employee emp; }
/** * @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; }
@Entity @Table( name = "CHILD" ) private static class Child { @EmbeddedId ChildKey id; @MapsId( "parent" ) @ManyToOne Parent parent; public String getfieldOnChildKeyParent() { // Note that there are two GETFIELD ops here, one on the field 'id' that should be enhanced and another // on the field 'parent' that may be or not (depending if 'extended enhancement' is enabled) // Either way, the field 'parent' on ChildKey should not be confused with the field 'parent' on Child return id.parent; } } }
/** * @author Emmanuel Bernard */ @Entity public class Dependent { @EmbeddedId DependentId id; @MapsId("empPK") @ManyToOne @JoinColumns( { @JoinColumn(nullable = false), @JoinColumn(nullable = false) }) Employee emp; }
@Entity(name = "Post") public static class Post { @Id private Integer id; @OneToOne(fetch = FetchType.LAZY) @MapsId @JoinColumn(name = "PD_ID", foreignKey = @ForeignKey(name = "FK_PD", value = ConstraintMode.NO_CONSTRAINT)) private PostDetails postDetails; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public PostDetails getPostDetails() { return postDetails; } public void setPostDetails(PostDetails postDetails) { this.postDetails = postDetails; } }
@Entity @Table( name = "PersonMapsIdSelectException" ) public static class PersonMapsIdSelectException extends Person { @Id private Long id; @OneToOne(fetch = FetchType.LAZY) @MapsId @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private City city; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public City getCity() { return city; } @Override public void setCity(City city) { this.city = city; } }
@Entity @Table( name = "PersonMapsIdColumnJoinException" ) public static class PersonMapsIdColumnJoinException extends Person { @Id private Long id; @OneToOne(optional = false, fetch = FetchType.LAZY) @MapsId @JoinColumn(name = "fk", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private City city; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public City getCity() { return city; } @Override public void setCity(City city) { this.city = city; } }
@Entity @Table( name = "PersonMapsIdColumnSelectExcept" ) public static class PersonMapsIdColumnSelectException extends Person { @Id private Long id; @OneToOne(optional = false, fetch = FetchType.LAZY) @MapsId @JoinColumn(name = "fk", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private City city; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public City getCity() { return city; } @Override public void setCity(City city) { this.city = city; } }
/** * @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; }
/** * @author Emmanuel Bernard */ @Entity @Table(name="`Dependent`") 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; }
@Embeddable public static class CityInEmbeddable { @OneToOne @MapsId @NotFound(action = NotFoundAction.IGNORE) @JoinColumn(name = "fk", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @Fetch(FetchMode.JOIN) private City city; public City getCity() { return city; } public void setCity(City city) { this.city = city; } } }
@Embeddable public static class CityInEmbeddable { @OneToOne @MapsId @NotFound(action = NotFoundAction.IGNORE) @Fetch(FetchMode.JOIN ) @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private City city; public City getCity() { return city; } public void setCity(City city) { this.city = city; } } }
@Embeddable public static class CityInEmbeddable { @OneToOne @MapsId @NotFound(action = NotFoundAction.IGNORE) @JoinColumn(name = "fk", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @Fetch(FetchMode.SELECT) private City city; public City getCity() { return city; } public void setCity(City city) { this.city = city; } } }
@Embeddable public static class CityInEmbeddable { @OneToOne @MapsId @NotFound(action = NotFoundAction.IGNORE) @Fetch(FetchMode.SELECT ) @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private City city; public City getCity() { return city; } public void setCity(City city) { this.city = city; } } }