Hi. There is next mapping
@Data
@Entity
@Table(name = "user_selections_log")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserSelectionLog {
@EmbeddedId
private UserSelectionLogId id;
@EqualsAndHashCode.Exclude
@ToString.Exclude
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "logged_as_merchant", insertable = false, updatable = false, nullable = false)
private Merchant loggedAsMerchant;
@EqualsAndHashCode.Exclude
@ToString.Exclude
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "selected_merchant", insertable = false, updatable = false, nullable = false)
private Merchant selectedMerchant;
@Column(nullable = false)
@UpdateTimestamp
private Timestamp lastSelectedAt;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Embeddable
public class UserSelectionLogId implements Serializable {
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "logged_as_merchant", nullable = false, unique = true))
})
private MerchantId loggedAsMerchant;
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "selected_merchant", nullable = false, unique = true))
})
private MerchantId selectedMerchant;
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "user_id", nullable = false, unique = true))
})
private UserId userId;
}
When I try to fetch object in Junit, EmbeddedId is mapped correctly, but loggedAsMerchant, selectedMerchant are NULL
Why?
When I try to fetch object via REST API - I get Hibernate Proxy in those fields
userSelectionLogRepository.save(
UserSelectionLog.builder()
.id(new UserSelectionLogId(currentMerchant.getId(), selectedMerchant.getId(), user.getId()))
.build());
Whats wrong with Junit? Please assist.