NullPointerException when accessing lazy loaded collection within DAO method NullPointerException when accessing lazy loaded collection within DAO method multithreading multithreading

NullPointerException when accessing lazy loaded collection within DAO method


I think you should use third join table like and use Criteria for loading collection.

    @OneToMany(fetch = FetchType.LAZY)    @JoinTable(name = "table", joinColumns = {@JoinColumn(name = "COLLECTION_ID", nullable = false)}, inverseJoinColumns = { @JoinColumn(name = "FOO_ID", nullable = true) })    private List<CollectionMember> collectionMembers = new ArrayList<CollectionMember>();@ManyToOne(mappedBy="collectionMembers")private CollectionCode collectionCode;


Problem is @NotFound(action = NotFoundAction.IGNORE)

This will create a returned object null instead of an empty collection in case no collection records are found. Remove and test it


Where does the multithreading come into play? How are ensuring that a single thread always uses the same hibernate session?

The way I understand hibernate and lazy loading, when you traverse the collection Hibernate will look in the CurrentSession. In a multithreaded environment that session may already have been used by another a thread. I'm not sure if the @Transactional is enough to preserve your same Hibernate Session.

There may be a Hibernate configuration for this.