Hi! Long time listener, first time caller. Using Hibernate 5.2.17.Final
I have an Entity with a one-to-many association. like this:
public class Location {
......
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, fetch = FetchType.LAZY)
@JoinColumn(name = "ledgerId")
protected LedgerValue ledgerValue;
The SQL to fetch is kind of complex, so i have a native query with a resultsetmapping, like this:
@ConstructorResult(
targetClass = LedgerValue.class,
columns = {
@ColumnResult(name = "lvid"),
@ColumnResult(name = "mainc", type = Long.class),
@ColumnResult(name = "emailonly", type = Boolean.class),
@ColumnResult(name = "copy", type = Boolean.class),
}
)
This all works fine, the Locations are loaded with data as expected. However, the âLedgerValueâ onetomany-object is always created, with null values if there are no values, since not all Locations have a LedgerValue.
This all works, my Location class gets populated with a LedgerValue entity. However, in the cases where there is no LedgerValue associated with a Location, i still get a LedgerValue object with only null values.
I would, rather, that the LedgerValue object itself is null if the âlvidâ identifier is null. I have looked around but havenât been able to find a way to do this, except for doing the entire sql myself, or a ResultSetExtractor.
I there a (hopefully simplish) way to accomplish this?
Pointers much appreciated.