My class
@Repository
public class UserRepositoryImp implements UserRepository {
private EntityManager entityManager;
@Autowired
public UserRepositoryImp(EntityManager entityManager) {
this.entityManager = entityManager;
}
@Override
public Integer getCountByEmail(String email) {
Session session = entityManager.unwrap(Session.class);
TypedQuery<User> query = session.createQuery("SELECT count(e) FROM User e WHERE e.email=:email", User.class);
query.setParameter("email", email);
return query.executeUpdate();
}
My Postman error
"Type specified for TypedQuery [com.TestMobileAppService.TestMobileAppService.Domain.User] is incompatible with query return type [class java.lang.Long]; nested exception is java.lang.IllegalArgumentException: Type specified for TypedQuery [com.TestMobileAppService.TestMobileAppService.Domain.User] is incompatible with query return type [class java.lang.Long]"
Please help me what is it problem???
You query in variable MY_SQL_COUNT_EMAIL
returns a count instead of User object, Change the data type of variable either to Long or Integer, something like given below
@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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.