
One To One Mapping
By:
akhilknambiar on
Jul 27th, 2012 | syntax:
Java | size: 0.87 KB | hits: 17 | expires: Never
@Entity
@Table(name = "Post")
public class Post {
private int id;
private Content content;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getId() {
return id;
}
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "content_id")
public Content getContent() {
return content;
}
public void setContent(Content content) {
this.content = content;
}
}
@Entity
@Table(name = "Content")
public class Content {
private int content_id;
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "post1"))
@Id
@GeneratedValue(generator = "generator")
public int getContent_id() {
return content_id;
}
public void setContent_id(int content_id) {
this.content_id = content_id;
}
}