Having an entity with more than one @OneToMany
associations and cascade = CascadeType.ALL
, if I invoke session.refresh() on that entity, one (and only one) of these associations gets loaded.
Example, with this model:
@Entity
@Table(name = "invoice")
public class Invoice {
@OneToMany(mappedBy = "invoice", cascade = CascadeType.ALL)
private List<Line> lines;
@OneToMany(mappedBy = "invoice", cascade = CascadeType.ALL)
private List<Tax> taxes;
...
}
If i do:
Session s = openSession();
Invoice invoice = s.get(Invoice.class, 1);
s.refresh(invoice);
I get from DB not only the invoice but also its lines, although I don’t get taxes.
Here you can find the complete example.
I’d expect not to have initialized any of its associations.
In any case what’s the point on initializing one of them (1st one?).
Is this a bug or an expected behavior.