我在调用这个允许我通过用户名获取用户的简单方法时遇到了这个问题:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long id;
@Constraints.Required
public String username;
@Constraints.Required
public String password;
public boolean isAdmin;
public static User findById(Long id) {
return JPA.em().find(User.class, id);
}
public void update(Long id) {
this.id = id;
JPA.em().merge(this);
}
public void save() {
JPA.em().persist(this);
}
public void delete() {
JPA.em().remove(this);
}
public static User findByUsername(String username) {
Query query = JPA.em().createQuery("select u from User u where username = :username", User.class);
query.setParameter("username", username);
return (User) query.getSingleResult();
}
}
错误到达查询创建,它是:
[IllegalArgumentException: Type specified for TypedQuery [models.User] is incompatible with query return type [interface java.util.Map]]
我正在使用 Hibernate 和 PlayFramework,有人知道如何解决这个问题吗?