There are three entities ChannelCore, ChannelLang, Question.
ChannelLang and ChannelCore has ManytoOne mapping. With ChannelLang has composite primary key (one of the attribute in the composite key is @MapsId with the ChannelCore primary key.
The Question entity has a ManytoOne relationship with ChannelLang.
All realtions are unidirectional . I want all the fetching to be lazy. i.e when ChannelLang fetch for Question as well ChannelCore fetch for ChannelLang.
Despite trying different ways , It is EAGER Fetch.
The boiled down code for Entities looks like:
@Entity
data class Question (
// unidirectional relation
@ManyToOne(cascade = [CascadeType.ALL],optional = false,fetch = FetchType.LAZY)
@JoinColumns(
JoinColumn(name = "channel_id"),
JoinColumn(name = "language")
)
val quesChannel:ChannelLang,
)
@Entity
data class ChannelLang(
@EmbeddedId
val id: ChannelLangId,
// though it is lazy, fetching channelLang fires channelCore automatically.
@ManyToOne(fetch = FetchType.LAZY,optional = false)
@JoinColumn(name = "channel_id",insertable = false,updatable = false)
val channelCore:ChannelCore
)
@Embeddable
data class ChannelLangId (
@Column(name = "channel_id")
val channelId:Long,
@Column(name = "language")
@Enumerated(EnumType.STRING)
val language: Languages
) : Serializable
@Entity
data class ChannelCore (
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "channel_id")
val id:Long
)