Skip to content

Instantly share code, notes, and snippets.

@thiagofa
Created May 24, 2014 05:23
Show Gist options
  • Save thiagofa/4ff456db032bc75eb025 to your computer and use it in GitHub Desktop.
Save thiagofa/4ff456db032bc75eb025 to your computer and use it in GitHub Desktop.
OneToOne com lazy
@Entity
public class A implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private B b;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@PrimaryKeyJoinColumn
@OneToOne(optional = false, fetch = FetchType.LAZY)
public B getB() {
return b;
}
public void setB(B b) {
this.b = b;
}
// equals e hashCode
}
@Entity
public class B implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private A a;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToOne(mappedBy = "b", optional = false, fetch = FetchType.LAZY)
public A getA() {
return a;
}
public void setA(A a) {
this.a = a;
}
// equals e hashCode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment