我試圖用Jackson/Hibernate/SQL/Java來進行選擇。Hibernate在Java中選擇查詢
這裏就是我想:
Transaction tx = null;
List<Note> list = null;
try {
tx = dbSession.beginTransaction();
Query query = dbSession.createQuery("select Note from notes where name= :nameQ and university= :universityQ " +
"and professor= :professorQ");
query.setParameter("nameQ", "ONE");
query.setParameter("universityQ", "TWO");
list = query.list();
tx.commit();
return new FileInfo(Integer.toString(list.size()), fileName);
}
但我得到一個nullptr例外,這顯然意味着什麼是錯的查詢。這有什麼問題?票據類是:
@Table(name="notes")
@Entity
public class Note {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name="id")
private int id;
@Column(name="name")
private String name;
@Column(name="course")
private String course;
@Column(name="university")
private String university;
@Column(name="date")
private String date;
@Column(name="professor")
private String professor;
@Column(name="semester")
private String semester;
@Column(name="url")
private String url;
public Note(){
}
public Note(String name, String course, String university, String date, String professor, String semester) {
this.name = name;
this.course = course;
this.university = university;
this.date = date;
this.professor = professor;
this.semester = semester;
}
//Usual setters/getters
你能幫我嗎?
您是否故意不設置'professorQ'參數? – khriskooper
@khriskooper哇,不知道我是如何錯過的..我會回覆你 – Bana
一般語法是「從註釋n中選擇n從哪裏...」 –