Lazy load one-to-one in JPA/Hibernate
Hibernate does not support one-to-one and lazy loading.
Workaround:
Use one-to-many in parent and ono-to-one in child.
@Entity
public class Task {
...
@OneToMany(mappedBy = "task", fetch = LAZY)
private Set<TaskResult> taskResult;
...
}
@Entity
public class TaskResult {
...
@OneToOne
@JoinColumn( name = "task_id")
private Task task;
...
}
Written by quartzde
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Hibernate
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#