Announcement Announcement Module
No announcement yet.
related one-to-many objects not obtained via JPA2 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • related one-to-many objects not obtained via JPA2

    Must be something very silly...
    Have a simple one to many relationship...One user related to many primaryPeople
    And the entity code captures this well as shown below:
    @OneToMany(mappedBy = "fkUserId", cascade = CascadeType.ALL)
    private Set<PrimaryPerson> primarypeople;
    @JoinColumn(name = "fk_user_id", referencedColumnName = "pk_user_id", nullable = false)
    private User fkUserId;

    In my service layer..have this
    public User findUser(java.lang.Integer id) {
    return userRepository.findOne(id);

    But when I get the user back it is not populated with a list/set of primaryPeople
    Why is there no eager-fetching? Should be by default.

    I have this code too for the UserRepository
    public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecificationExecutor<User> {
    Also pom says this

    I could do it via a Specification. or a NamedQuery..but that would be crude when using JPA
    This kinda thing is out of the what is amiss?

  • #2
    I plan to use this solution from one Graham Smith..

    Basically it schools me "OneToMany relationship is lazy loaded by default under JPA"
    So will try this: @OneToMany( fetch= FetchType.EAGER )