I want to map a @OneToOne association using Hibernate 5.3.10 and JPA.
I know that the parent side of a @OneToOne association cannot be loaded lazily when not using bytecode enhancements.
In this case, I only want to map the client side and use @MapsId association which is suggested here: Best way to map onetoone
Here is my mapping on the Client side.
The parent side CardEntity has no mapping to the DeviceType at all.
public class DeviceType {
@Id
@Column( name = "PRODUCT_CARD_TYPE_ID" )
private Long cardTypeId;
...
@OneToOne( fetch = FetchType.LAZY )
@MapsId
@JoinColumn( name = "PRODUCT_CARD_TYPE_ID" )
private CardEntity card;
....
}
I give it an extra @JoinColumn because the KEY column in the CardEntity has a different name than "PRODUCT_CARD_TYPE_ID".
See Change Id Column
For this mapping, LAZY loading does not work. It always executes another statement to fetch the CardEntity. What I am doing wrong here?