内存中的Hibernate / HSQLDB:java.sql.SQLSyntaxErrorException:用户缺少特权或找不到对象

时间:2018-12-27 21:40:08

标签: hibernate exception hsqldb

我正在使用hibernate /在内存hsqldb中构建简单的crud应用程序,而没有spring。

我认为这可能是版本不兼容,但是升级没有帮助。我试图将hbm2ddl.auto更改为“ update”,但效果也不好。

例外:

java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: ACCOUNT

Sql:

insert into Account (id, balance, creationDate, currency, isActive, lastModificationDate, username) values (default, ?, ?, ?, ?, ?, ?)

消息:

could not prepare statement

实体:

@Entity
@Getter
@Setter
public class Account {

    @Id
    @GeneratedValue
    private String id;

    @Column(length = 16)
    private String username;
    @Column(precision = 2)
    private BigDecimal balance;
    private Currency currency;
    private boolean isActive;
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationDate;
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastModificationDate;
}

方法:

@Override
public String save(Account account) {
    Session session = SessionUtil.getSesssionFactory().openSession();
    Transaction transaction = null;
    String id = null;
    try {
        transaction = session.beginTransaction();
        id = String.valueOf(session.save(account));
        transaction.commit();
    }
    catch (HibernateException e){
        transaction.rollback();
    }
    finally {
        session.close();
    }
    return id;
}

配置:

public static SessionFactory getSesssionFactory(){
    Configuration cfg = new Configuration()
            .addAnnotatedClass(Transfer.class)
            .addAnnotatedClass(Account.class)
            .setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect")
            .setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:mydb")
            .setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver")
            .setProperty("hibernate.connection.username", "sa")
            .setProperty("hibernate.connection.password", "")
            .setProperty("hibernate.hbm2ddl.auto", "create-drop");
    SessionFactory sessionFactory = cfg.buildSessionFactory();
    return sessionFactory;
}

pom.xml:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.6.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.2.9</version>
    </dependency>

0 个答案:

没有答案