Hello, i have a problem with fetching through EmbeddedId field, here is the field:
@OneToMany(fetch = FetchType.LAZY, targetEntity = User_GameSession.class, mappedBy = "userGameSessionCK.gameSession")
private List<User_GameSession> gameSession_users;
The related class:
@Table(name = "user_to_game_session")
@Entity
@EntityListeners(value = {UsersNumForGameSessionManager.class})
@Getter
@Setter
@NoArgsConstructor
public class User_GameSession {
@EmbeddedId
private User_GameSessionCK userGameSessionCK;
public User_GameSession(User user, GameSession gameSession) {
this.userGameSessionCK = new User_GameSessionCK();
this.userGameSessionCK.setUser(user);
this.userGameSessionCK.setGameSession(gameSession);
}
}
The embeddable class:
@Getter
@Setter
@NoArgsConstructor
@Embeddable
public class User_GameSessionCK implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
protected User user;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "game_session_id")
protected GameSession gameSession;
public User_GameSessionCK(User user, GameSession gameSession) {
this.user = user;
this.gameSession = gameSession;
}
}
And fetching chain logic:
root.fetch("gameSession_users", JoinType.LEFT).fetch("userGameSessionCK", JoinType.LEFT).fetch("user", JoinType.LEFT)
It traps into infinite loop inside org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping.createCircularBiDirectionalFetch
method on 1259 line of code
...
while ( realFetchParent.getNavigablePath() != parentNavigablePath ) {
realFetchParent = ( (Fetch) fetchParent ).getFetchParent();
}
...
Is it resolvable with using of EmbeddedId field or i have to use another mapping strategy?
Hibernate version: 6.6.11.Final