'Spring @GenericGenerator ignoring Object relationships
I'm having some issues using Springs @GenericGenerator with an object with a @ManyToMany relationship. The generator is wired up correctly, and is being used to generate an ID for my entity. However, the @ManyToMany entity that i'm using the generate the ID seems to be missing when the generate method is called.
I have my first Entity, with the generator and the relationship
public class Donor {
@Id
@GenericGenerator(name = "donor_id", strategy = "path.to.my.CustomDonorIdGenerator")
@GeneratedValue(generator = "donor_id")
private String id;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<Address> addresses = new HashSet<>();
...more fields and good stuff
When I stop the code on a breakpoint before my repository.save() the Donor object has the relationship:
However, my next break point within the generator is missing the addresses:
@Override
public Serializable generate(SharedSessionContractImplementor session, Object o) throws HibernateException {
Connection connection = session.connection();
try {
Donor donor = (Donor) o;
... generate the stuff.
I did notice that the Object number is different - so I'm assuming it's creating a copy of the object, but not correctly carrying over the relationship. Is there some way to carry this over correctly?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


