带有EclipseLink JPA的HSQLDB不能持续进行一次事务处理

时间:2019-04-15 02:58:12

标签: jpa eclipselink hsqldb

我正在使用HSQLDB文件存储来快速检索数据。我正在使用EclipseLink for JPA。我已经遵循了文档中的所有内容,但是数据并未持久存储在文件中。我想将该文件用作持久性存储,并且数据不应丢失。

如果我在同一事务中插入数据并对其进行查询,它将返回保存的数据。但是,如果我单独查询,则数据不存在。

**This is my persistence.xml**

 <persistence-unit name="bridge"
                  transaction-type="RESOURCE_LOCAL">

 <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:file:datastore/bridgedb;shutdown=true;hsqldb.write_delay=false;" />
        <property name="javax.persistence.jdbc.user" value="xyz_user" />
        <property name="javax.persistence.jdbc.password" value="xyz_user" />

        <property name="javax.persistence.schema-generation.database.action" value="none"/>
        <property name="javax.persistence.schema-generation.create-source" value="script"/>
        <property name="javax.persistence.schema-generation.drop-source" value="script"/>
        <property name="javax.persistence.sql-load-script-source" value="sql/create_schema.sql"/>
        <property name="eclipselink.logging.level" value="FINE"/>

        <property name="eclipselink.connection-pool.default.initial" value="1" />
     </properties>

   </persistence-unit>

DaoImpl.java
@Override
public void saveObject(MyObject myObject) {

    try {
        txn.begin();

        entityManager.persist(myObject);
        MyObject newObj = entityManager.find(MyObject.class, myObject.getId());
        // newObj has the stuff saved earlier

        txn.commit();

    } catch (Exception e) {
        log.debug("Exception occurred while saving RRNInfo ", e);
        txn.rollback();
    }

 }

  // Here, it saves fine.

    @Override
    public MyObject getObject(String key) {
    MyObject myObject = null;
    try {
        txn.begin();
        myObject = entityManager.find(MyObject.class, key);

    } catch (Exception e) {
        log.debug("Exception occurred while retrieving RRNInfo", e);
        txn.rollback();
    }
    entityManager.close();

    return myObject;
  }

  // Here, it is gone. There is nothing in the database. 

此外,似乎每次都会触发一个sql查询,该表会重新   即使将schema-generation.database.action更改为无,也可以创建。

有什么想法吗?

0 个答案:

没有答案