title: Entity-in-Entity, infinite recursive data access issues
body: <p>I have two entities, and two POJO versions of the entities for data access.  What I can't quite figure out is how to properly utilize the POJOs to avoid infinite recursive data access when I perform API calls (basic CRUD).  I don't want to suppress this with @JsonIgnore, I want to fix this with a proper DAO/DTO layer but am not quite sure how.  Should I remove <code>Set&lt;Game&gt;</code> and <code>Set&lt;Player&gt;</code> from the POJOs and make the appropriate changes, or should I do something else?  Thank you!</p>
  <pre><code>@Entity
  public class GameEntity {
    private String gameName;
  
    @ManyToMany
      @JoinTable(
        name = &quot;gameInformation&quot;,
        joinColumns = @JoinColumn(name = &quot;game_id&quot;),
        inverseJoinColumns = @JoinColumn(name = &quot;player_id&quot;))
    private Set&lt;PlayerEntity&gt; players;
  }
  
  @Entity
  public class PlayerEntity {
    private String playerName;
  
    @ManyToMany(mappedBy = &quot;players&quot;)
    private Set&lt;GameEntity&gt; gamesPlayed;
  }
  
  @Transactional
  public void assignPlayersAndGames(String gameName, String playerName) {
    GameEntity gameEntity = gameRepository.findGameByName(gameName);
    PlayerEntity playerEntity = playerRepository.findPlayerByName(playerName);
  
    gameEntity.setPlayers(playerEntity);
    playerEntity.setGamesPlayed(gameEntity);
  }
  
  public Set&lt;Player&gt; getPlayers() {
    Set&lt;Player&gt; allPlayers = new HashSet&lt;&gt;();
    for (PlayerEntity player : this.players) {
      allPlayers.add(toPlayer(player));
  
    return allPlayers;
  }
  
  public Set&lt;Game&gt; getGamesPlayed() {
    Set&lt;Player&gt; allGamesPlayed = new HashSet&lt;&gt;();
    for (GameEntity game : this.gamesPlayed) {
      allGamesPlayed.add(toGame(game));
  
    return allGamesPlayed;
  }
  
  public Game toGame(GameEntity gameEntity) {
    return new Game(gameEntity.getGameName(), gameEntity.getPlayers());
  }
  
  public Player toPlayer(PlayerEntity playerEntity) {
    return new Player(playerEntity.getPlayerName(), playerEntity.getGamesPlayed());
  }
  </code></pre>
  <pre><code>public class Game {
    private String gameName;
    private Set&lt;Player&gt; players;
  }
  
  public class Player {
    private String playerName;
    private Set&lt;Game&gt; gamesPlayed;
  }
  </code></pre>
  <p>UPDATE:  I have removed the <code>Set&lt;T&gt;</code> members from the non-entity POJOS.  The flow now goes getGameEntity -&gt; toGame -&gt; toEntity (same for Player) and this currently works.  If there is a better/more proper way to do this, I'd love to know!</p>