没找到命名查询

时间:2016-08-15 17:47:00

标签: spring hibernate repository entity spring-data-jpa

我有这个实体:

@Entity
public class User {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false)
private Long id;

private String firstname;
private String lastname;
private Date birthdate;
private int phonenumber;
private int cin;
private String address;
private String password;
private String email;
//Getters & Setters ..
}

这个DAO课程:

@Repository
public interface UserDAO extends JpaRepository<User, Long> {

List<User> findAllUsersByFirstnameOrderByFirstnameDesc(String firstName);
List<User> findAllUsersByLastnameOrderByLastnameDesc(String Lastname);
List<User> findAllUsersByFirstnameAndLastnameOrderByFirstname(String firstAndLastname);
List<User> findAllUsersByFirstnameOrLastnameContaining(String nameContent);
List<User> findAllUsersByPhonenumber(int phoneNumber);
List<User> findAllUsersByEmailContaining(String email);
User findUserByCin(int cin);
}

当我运行它时,我收到了这个错误:

  

引起:java.util.NoSuchElementException:null       at java.util.ArrayList $ Itr.next(Unknown Source)

     

DEBUG org.springframework.data.jpa.repository.query.NamedQuery - 未找到命名查询User.findAllUsersByEmailContaining

     

DEBUG org.springframework.data.jpa.repository.query.NamedQuery - 未找到命名查询   User.findAllUsersByFirstnameOrLastnameContaining

感谢。

1 个答案:

答案 0 :(得分:0)

感谢@Arun,我能够解决下面提到的问题:

改变这个:

List<User> findAllUsersByFirstnameAndLastnameOrderByFirstname(String firstAndLastname);

致:

List<User> findAllUsersByFirstnameAndLastnameOrderByFirstname(String firstname, String lastname);

这个:

List<User> findAllUsersByFirstnameOrLastnameContaining(String nameContent);

List<User> findAllUsersByFirstnameOrLastnameLike(String nameContent);

这个

List<User> findAllUsersByFirstnameOrLastnameContaining(String nameContent);

List<User> findAllUsersByFirstnameOrLastnameContaining(String firstname, String lastname);

有关详细信息,请查看此link