我遇到了一個問題 - 我是hibernate的新手,需要投一個表,由executing session.createSQLQuery(query).list()
命令返回。 我嘗試添加addEntity(Result.class)
命令,但程序會拋出異常:將默認的hibernate createSQLQuery轉換爲自制類的列表
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.MappingException: Unknown entity: com.hib.entities.Result
在mysql中我的成績表看起來像這樣:
| bookName | authorSurname | authorFirstName | authorPatronymic | releaseDate | amountBooks|
我試圖創建實體類結果和註釋它,但似乎我失敗了。 我的實體類看起來是這樣的:
package com.hib.entities;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table
public class Result {
String bookName;
String authorSurname;
String authorFirstName;
String authorPatronymic;
Integer releaseDate;
Integer amountBooks;
public Result(String bookName, String authorSurname, String authorFirstName, String authorPatronymic, Integer releaseDate, Integer
amountBooks) {
this.bookName = bookName;
this.authorSurname = authorSurname;
this.authorFirstName = authorFirstName;
this.authorPatronymic = authorPatronymic;
this.releaseDate = releaseDate;
this.amountBooks = amountBooks;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public void setAuthorSurname(String authorSurname) {
this.authorSurname = authorSurname;
}
public void setAuthorFirstName(String authorFirstName) {
this.authorFirstName = authorFirstName;
}
public void setAuthorPatronymic(String authorPatronymic) {
this.authorPatronymic = authorPatronymic;
}
public void setReleaseDate(Integer releaseDate) {
this.releaseDate = releaseDate;
}
public void setAmountBooks(Integer amountBooks) {
this.amountBooks = amountBooks;
}
public String getBookName() {
return bookName;
}
public String getAuthorSurname() {
return authorSurname;
}
public String getAuthorFirstName() {
return authorFirstName;
}
public String getAuthorPatronymic() {
return authorPatronymic;
}
public Integer getReleaseDate() {
return releaseDate;
}
public Integer getAmountBooks() {
return amountBooks;
}
@Override
public String toString() {
return "Result{" +
"bookName='" + bookName + '\'' +
", authorSurname='" + authorSurname + '\'' +
", authorFirstName='" + authorFirstName + '\'' +
", authorPatronymic='" + authorPatronymic + '\'' +
", releaseDate=" + releaseDate +
", amountBooks=" + amountBooks +
'}';
}
}
能否請你幫我解決這個問題?