Hibernate QuerySyntaxException表未映射

时间:2018-11-13 13:29:54

标签: java postgresql hibernate

当我尝试使用Hibernate创建对数据库的任何查询时, 我犯了同样的错误: Error code

DaoMethod:

@Override
public List findAll() {
    openCurrentSessionWithTransaction();
    List books = currentSession.createQuery("from AuthorEntity").list();
    closeCurrentSessionWithTransaction();
    return books;
}

AuthorEntity(设置字母和哈希码等号,但隐藏):

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

1 个答案:

答案 0 :(得分:0)

可以为您的sessionFactory尝试此代码吗?它帮助了我

final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure().build();
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();