Announcement Announcement Module
Collapse
No announcement yet.
Converting native mysql count to an int instead of a BigInteger using JPARepository? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converting native mysql count to an int instead of a BigInteger using JPARepository?

    Hi,

    Im using JPARepository and have the following native mysql query defined on my entity

    Code:
    @Entity
    @DiscriminatorValue(value = User.NEW_USER_TYPE)
    @SqlResultSetMappings(
        @SqlResultSetMapping(name="countMapping",
        columns=[
            @ColumnResult(name="count")
            ]
        )
    )
    @NamedNativeQueries([
        @NamedNativeQuery(name="UserNew.countFacebookFriends",query="select count(*) as count from ql_user where type='NEW' and id in (select friend from ql_friends where user=:userId) and exists (select userId from ql_facebook_info where userId=id)",resultSetMapping="countMapping")
    ])
    @Slf4j
    class UserNew extends User {
    ..


    in my interface I seem to have no option but to return a BigIntger and cast it in the caller:

    Code:
    @Repository
    public interface UserNewDao extends JpaRepository<UserNew, Long> {
    
        /**
         * this maps to native query defined in entity
         * */
        BigInteger countFacebookFriends(@Param("userId") Long userId)
    
    }
    is there anyway I can have it mapped to an int (or long) in the forst place, just to keep things more concise ?

    thanks
Working...
X