当我尝试用Hibernate创建任何数据库查询时,我得到了同样的错误:错误代码
DaoMethod:
@Override
public List findAll() {
openCurrentSessionWithTransaction();
List books = currentSession.createQuery("from AuthorEntity").list();
closeCurrentSessionWithTransaction();
return books;
}
AuthorEntity(Setter和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
你能为你的sessionFactory尝试一下这个代码吗。它帮助了我
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure().build();
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();