ClassCastException: Integer cannot be cast to Long, while trying to iterate over entity IDs
<p>I have following method in my service: </p>

<pre><code>public Set&lt;BoardCard&gt; moveHoldedCardsToNewBoard(Board newBoard, Board prevBoard) {
        Set&lt;BoardCard&gt; boardCards = new HashSet&lt;&gt;();
        if (prevBoard != null) {
            List&lt;Long&gt; holdedCardIds = getExcludedCardIds(prevBoard);
            for (Long item: holdedCardIds) {

            }
    }
</code></pre>

<p>When I want to loop the <code>holdedCardIds</code> list, I received: <strong>java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long</strong>  in this place -> <code>for (Long item: holdedCardIds) {</code></p>

<p>My getExcludedCardIds() looks like: </p>

<pre><code>@Override
public List&lt;Long&gt; getExcludedCardIds(Board board) {

        return boardCardRepository.getExcludedCardIds(board.getId());
    }
</code></pre>

<p>Repository: </p>

<pre><code>@Repository
public interface BoardCardRepository extends JpaRepository&lt;BoardCard, Long&gt;, QueryDslPredicateExecutor&lt;BoardCard&gt; {

    @Query(value = "SELECT bc.card_id FROM boards_cards bc WHERE bc.board_id =:boardId AND bc.on_hold=true", nativeQuery = true)
    List&lt;Long&gt; getExcludedCardIds(@Param("boardId") Long boardId);
}
</code></pre>

<p>Entites:</p>

<pre><code>@Entity
@NamedEntityGraph(name = "graph.BoardCard", attributeNodes = {})
@Table(name = "boards_cards")
public class BoardCard implements Serializable {

    private static final long serialVersionUID = -9019060375256960701L;

    @EmbeddedId
    private BoardCardId id = new BoardCardId();

}
@Embeddable
public class BoardCardId implements Serializable {

    private static final long serialVersionUID = -3630484760647866357L;

    @ManyToOne
    private Board board;

    @ManyToOne
    private Card card;
}

    @Entity
    @Table(name = "boards")
    public class Board extends BaseEntity implements Serializable {
        @Id
        @SequenceGenerator(name = "boards_id_seq", sequenceName = "boards_id_seq", allocationSize = 1)
        @GeneratedValue(strategy = GenerationType.AUTO, generator = "boards_id_seq")
        private Long id;
}




 @Entity    
   @Table(name = "cards")     
   public class Card extends BaseEntity implements Serializable {

                @Id
                @SequenceGenerator(name = "cards_id_seq", sequenceName = "cards_id_seq", allocationSize = 1)
                @GeneratedValue(strategy = GenerationType.AUTO, generator = "cards_id_seq")
                private Long id;
}
</code></pre>

<p>In my POSTGRES schema.sql the BoardCard entity is defined, as follows: </p>

<pre><code>CREATE TABLE IF NOT EXISTS boards_cards(
                board_id INTEGER,
                card_id INTEGER,
                on_hold BOOLEAN DEFAULT FALSE,
                CONSTRAINT pk_user_card PRIMARY KEY (board_id, card_id),
                FOREIGN KEY(board_id) REFERENCES boards(id),
                FOREIGN KEY(card_id) REFERENCES cards(id)
            );
</code></pre>

<p>I have found <a href="https://stackoverflow.com/questions/3245220/whats-equivalent-to-long-data-type-in-postgresql">here</a> , that equivalent of LONG type in postgresql is <code>bigint</code> . But, If I try to use it, how it will affect on the performance side of my app?  </p>

<p>So, tell how can I solve this issue?</p>