java - JPA 抛出 - "ERROR: user lacks privilege or object not found: BOOK"

标签 java spring hibernate jpa hsqldb

在我的项目中,我使用 HSQLDB 作为数据库。构建了数据库并添加了两个条目。现在我正在尝试使用 JPA 获取这些条目。不幸的是,出现以下异常

ERROR: user lacks privilege or object not found: BOOK javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602) at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:492) at com.top.shelf.lib.entityManagers.BookManager.main(BookManager.java:48) Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1928) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1897) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1875)

这是我的 persistance.xml 文件。

    <class>com.top.shelf.lib.entityManager.Book</class>

    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:MyDB" />
        <property name="javax.persistence.jdbc.user" value="sa" />
        <property name="javax.persistence.jdbc.password" value="" />
        <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
    </properties>
</persistence-unit>

还有我的实体类:

@Entity
@Table(name = "BOOK")
public class Book {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private int id;

    @Column(name = "TITLE")
    private String title;

    @Column(name = "AUTHOR")
    private String author;

    @Column(name = "BRIEF_DESCRIPTION")
    private String description;

    @Column(name = "ISBN")
    private String isbn;

    @Column(name = "LOCATION")
    private String location;

    @Column(name = "USER_ID")
    private String user_id;

    public Book(String title, String author, String description, String isbn,
            String location) {
        this.title = title;
        this.author = author;
        this.description = description;
        this.isbn = isbn;
        this.location = location;
    }

    public int getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public String getAuthor() {
        return author;
    }

    public String getDescription() {
        return description;
    }

    public String getIsbn() {
        return isbn;
    }

    public String getLocation() {
        return location;
    }

    public String getUser_id() {
        return user_id;
    }

}

最佳答案

尝试:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
      <persistence-unit name="manager" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <class>com.top.shelf.lib.entityManager.Book</class>

        <properties>
          <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
          <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:MyDB"/>
          <property name="javax.persistence.jdbc.user" value="sa"/>
          <property name="javax.persistence.jdbc.password" value=""/>
          <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
          <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>
      </persistence-unit>
    </persistence>

关于java - JPA 抛出 - "ERROR: user lacks privilege or object not found: BOOK",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34808894/

相关文章:

java - 安卓/Java : Fragment instantiating causes memory leak?

java - 有没有办法提高 Java 编译器的多核/多处理器性能?

spring - 无法从gradle命令行传递spring配置文件

java - 当我将其部署在 openshift 上时,我的 WEB 应用程序中的搜索仅适用于拉丁符号,但它在我的本地计算机上运行良好

java - SwitchYard Maven项目出现问题

java - JSON 对象从 api 随机变化

java - Spring Data Rest 和计数查询

java - 将 RuntimeBeanRefrence 用于对象列表时出现 ConversionNotSupportedException

java - hibernate - 如何为java类正确生成.hbn.xml映射文件,该文件对应于具有复合主键的表?

hibernate - spring data jpa @Entity属性未找到异常