When I try to create any query to database with Hibernate, i get the same error: Error code
DaoMethod:
@Override
public List findAll() {
openCurrentSessionWithTransaction();
List books = currentSession.createQuery("from AuthorEntity").list();
closeCurrentSessionWithTransaction();
return books;
}
AuthorEntity(Setters and hashcode&equals are present but hidden):
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;
}
}
Why does this error occur? I do this on IntellijIdea 2018, Java 1.8. hibernate.cfg.xml
Can you try this code for your sessionFactory. It helped me
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure().build();
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.