【发布时间】:2018-11-13 13:29:53
【问题描述】:
当我尝试使用 Hibernate 创建对数据库的任何查询时, 我犯了同样的错误: Error code
道法:
@Override
public List findAll() {
openCurrentSessionWithTransaction();
List books = currentSession.createQuery("from AuthorEntity").list();
closeCurrentSessionWithTransaction();
return books;
}
AuthorEntity(Setters 和 hashcode&equals 存在但隐藏):
import javax.persistence.*;
import java.util.Objects;
@Entity
@Table(name = "author")
public class AuthorEntity {
private long authorId;
private String name;
@Id
@Column(name = "author_id")
public long getAuthorId() {
return authorId;
}
@Basic
@Column(name = "name")
public String getName() {
return name;
}
}
为什么会出现这个错误?我在 IntellijIdea 2018,Java 1.8 上执行此操作。 hibernate.cfg.xml
【问题讨论】:
-
很可能是配置错误
-
请发布您的 Hibernate 配置文件(hibernate.cfg.xml 等)
-
请将配置添加到问题正文中,而不是作为评论。
-
你能更新整个 AuthorEntity 类吗?只是想看看你的进口。
-
我认为你使用了“org.hibernate.annotations.Entity”注解。
标签: java postgresql hibernate