1

I have three objects: A, B, and C.

A has a one-to-many relationship with B.

B has a one-to-many relationship with C.

The classes are as follow:

public class A {
   @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
   @JoinTable(...)
   Set<B> getBSet();
}

public class B {
   @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
   @JoinTable(...)
   Set<C> getCSet();
}

When I used session.get(A.class, id) (session is a Hibernate object and I already had the A instance saved in the database with one set of B and 1 set of C) to get a persistent object of class A with the provided id, I got the following exception:

Apr 12, 2018 4:44:25 PM org.hibernate.event.internal.DefaultLoadEventListener onLoad
INFO: HHH000327: Error performing load command : org.hibernate.PropertyAccessException: Exception occurred inside setter of com.example.B.cSet

The setter in B is:

public void setCSet(Set<C> cSet) {
   this.cSet = cSet;
   ...
}

I thought I already forced everything to be eagerly loaded, but somehow it didn't work the way I wanted.

Any ideas what has happened and how should I fix it?

Thank you for your time.

0

1 Answer 1

0

Try to move all annotations to fields instead of annotating methods. It looks like that annotating methods instead of fields breaks eager loading. Look at this question, looks similar to yours: What cause org.hibernate.PropertyAccessException: Exception occurred inside setter

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.