39 lines
904 B
Java
Executable File
39 lines
904 B
Java
Executable File
package com.ankurm.hibernatedemo.association;
|
|
|
|
import jakarta.persistence.Entity;
|
|
import jakarta.persistence.FetchType;
|
|
import jakarta.persistence.GeneratedValue;
|
|
import jakarta.persistence.GenerationType;
|
|
import jakarta.persistence.Id;
|
|
import jakarta.persistence.JoinColumn;
|
|
import jakarta.persistence.OneToOne;
|
|
import jakarta.persistence.Table;
|
|
|
|
/** Owning side (holds {@code user_id} FK) of {@link LazyUser#getProfile()}. */
|
|
@Entity
|
|
@Table(name = "lazy_profile")
|
|
public class LazyProfile {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
private String bio;
|
|
|
|
@OneToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "user_id")
|
|
private LazyUser user;
|
|
|
|
protected LazyProfile() {
|
|
}
|
|
|
|
public LazyProfile(String bio, LazyUser user) {
|
|
this.bio = bio;
|
|
this.user = user;
|
|
}
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
}
|