JavaSpringBootWeb服务

JavaSpringBootWeb服务,java,spring,Java,Spring,我的班级 @存储库 公共类UserRepositoryImp实现UserRepository{ 私人实体管理者实体管理者; @自动连线 公共用户RepositoryImp(EntityManager EntityManager){ this.entityManager=entityManager; } @凌驾 公共整数getCountByEmail(字符串电子邮件){ Session Session=entityManager.unwrap(Session.class); TypedQuery=

我的班级

@存储库
公共类UserRepositoryImp实现UserRepository{
私人实体管理者实体管理者;
@自动连线
公共用户RepositoryImp(EntityManager EntityManager){
this.entityManager=entityManager;
}
@凌驾
公共整数getCountByEmail(字符串电子邮件){
Session Session=entityManager.unwrap(Session.class);
TypedQuery=session.createQuery(“从用户e中选择计数(e),其中e.email=:email”,User.class);
query.setParameter(“email”,email);
返回query.executeUpdate();
}
我的邮差错误

“为TypedQuery[com.TestMobileAppService.TestMobileAppService.Domain.User]指定的类型为” 与查询返回类型[class java.lang.Long]不兼容;嵌套异常为 java.lang.IllegalArgumentException:为TypedQuery指定的类型 [com.TestMobileAppService.TestMobileAppService.Domain.User]与查询返回类型不兼容 [class java.lang.Long]“


请帮助我有什么问题?

您在变量
MY\u SQL\u COUNT\u EMAIL
中查询时返回一个计数而不是用户对象,请将变量的数据类型更改为Long或Integer,如下所示

@Override
public Integer getCountByEmail(String email) {
  Session session = entityManager.unwrap(Session.class);
  
     TypedQuery<Integer> query = session.createQuery(MY_SQL_COUNT_EMAIL,Class.forName();
     query.setParameter("email", email);    
      return query.executeUpdate();
}
@覆盖
公共整数getCountByEmail(字符串电子邮件){
Session Session=entityManager.unwrap(Session.class);
TypedQuery query=session.createQuery(MY_SQL_COUNT_EMAIL,Class.forName();
query.setParameter(“email”,email);
返回query.executeUpdate();
}

请阅读:
select count
返回一个整数,但您键入的查询需要一个用户实例。请将键入的查询更改为具有
,并进行相应更新,或者修复您的查询以返回一个非数字的用户。class forname需要PareMeters不工作class.forname()删除Class.forName参数,并在createQuery方法中仅保留查询