Created
May 24, 2014 05:23
-
-
Save thiagofa/4ff456db032bc75eb025 to your computer and use it in GitHub Desktop.
OneToOne com lazy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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