Last Updated: February 25, 2016
·
3.622K
· quartzde

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;
...
}