I read Spring JPARepository Data: how to conditionally invoke child users . But I want to use convenient JPA annotations, rather than manually connecting all the children.
Let's say I have the following model:
@Entity public class UserModel extends BaseModel<User> { @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List<CredentialModel> credentialList = new ArrayList<>(); @ManyToMany @JoinTable( name = "users_actions", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "action_id", referencedColumnName = "id") ) private List<ActionMode> actionList = new ArrayList<>(); }
Retrieving credentialList
and actionList
can take a lot of time (combine selections, etc.). I do not want to automatically extract credentialList
and actionList
. But when I call them, I expect them to be an empty list, not a LazyInitializationException
.
Can I use fields even if I don’t specifically JOIN FETCH
them in @Query
. Just leave it blank.
If not, is it all the same to achieve the same needs?
source share