java - Spring Data JPA ClassCastException: Integer cannot be cast to Long -
in spring data application ran similar problem described here classcastexception: integer cannot cast long, while trying iterate on entity ids
this entity:
@table(name = "users") public class user extends baseentity implements serializable { private static final long serialversionuid = 5088960286161030648l; @id @sequencegenerator(name = "users_id_seq", sequencename = "users_id_seq", allocationsize = 1) @generatedvalue(strategy = generationtype.auto, generator = "users_id_seq") private long id; ... }
and spring data repository method:
@query(value = "select u.user_id users u u.game_id =:gameid", nativequery = true) list<long> getgameids(@param("gameid") long gameid);
which going return list of long type after execution returns list of integer , application fails
java.lang.classcastexception: java.lang.integer cannot cast java.lang.long
how tell spring data or jpa return list of long
(not integer
) in result list ?
i don't want cast values(integer long) in run-time.
also, main criterion of application performance idea switch ids long
integer
in entities ? practice use integer
instead of long
in jpa entity id ?
updated
i use postgresql
in case of:
user_id integer
i'm receiving - java.lang.classcastexception: java.lang.integer cannot cast java.lang.long
user_id bigint
i'm receiving - java.lang.classcastexception: java.math.biginteger cannot cast java.lang.long
problem when using native query long
class doesn't corellate database type — getlong doesn't work there. should 1 of following
- change type in db , in app biginteger (if integer not enough needs)
- change type in db , in app integer (if it's enough needs)
- remove nqtivequery attribute , use clear jpql.
Comments
Post a Comment