HSQLDB和Hibernate / JPA - 不会持久化到磁盘? [英] HSQLDB and Hibernate/JPA - not persisting to disk?

查看:141
本文介绍了HSQLDB和Hibernate / JPA - 不会持久化到磁盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  em.getTransaction()。begin();这是一个使用HSQL和Hibernate的新手。 
for(Activity theActivity:activities){
em.persist(theActivity);
}
em.getTransaction()。commit();
em.close();

后面是...

  EntityManager em = emf.createEntityManager(); 
em.getTransaction()。begin();
System.out.println(QUERY ::
+ em.createQuery(SELECT COUNT(*)FROM+ Activity.class.getName())。getSingleResult()
。的toString());
em.getTransaction()。commit();

打印25000(活动中的活动对象数)。但是当我再次运行此测试时,计数(*)中的对象数量不会增加(并且在程序开始时为0)。因此,这些对象不会变得持久。



这是我的hsqldb连接字符串:

  name =hibernate.connection.urlvalue =jdbc:hsqldb:file:data / cmon

所以它不是一个内存中的数据库,据我所知...



有没有人有任何想法,为什么对象没有得到坚持超越单个JVM会话?很高兴能提供更多的信息,但是与Hibernate / JPA / HSQL有很多相关的状态,所以我们不清楚究竟是什么相关的。


有没有人有任何想法,为什么这些对象不会在单个JVM会话之外持久保存?

在提交后,HSQLDB不会立即将更改写入磁盘(请参阅 WRITE DELAY ),HSQLDB在默认情况下是不可持久的(这来自performance来自哪里)。



尝试在连接字符串中设置连接属性 shutdown = true ,以获取上次连接结束时写入的更改。

  jdbc:hsqldb:file:data / cmon; shutdown = true 

如果没有帮助,请尝试设置 WRITE DELAY 为0(或false)。如果您使用HSQLDB 1.8.x,请使用SQL命令:

  SET WRITE_DELAY 0 


$ b

.net / doc / 2.0 / guide / dbproperties-chapt.htmlrel =noreferrer>属性 hsqldb.write_delay

  jdbc:hsqldb:file:data / cmon; hsqldb.write_delay = false 


Something of an novice with HSQL and Hibernate...

em.getTransaction().begin();
for (Activity theActivity : activities) {
  em.persist(theActivity);
}
em.getTransaction().commit();
em.close();

followed by...

EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
System.out.println("QUERY:: "
    + em.createQuery("SELECT COUNT(*) FROM " + Activity.class.getName()).getSingleResult()
        .toString());
em.getTransaction().commit();

Prints 25000 (the number of Activity objects in activities). But when I run this test again, the number of objects in the count(*) doesn't increase (and is 0 at the beginning of the program). So the objects aren't getting durably written.

This is my hsqldb connection string:

name="hibernate.connection.url" value="jdbc:hsqldb:file:data/cmon"

so it's not an in-memory database as far as I know...

Does anyone have any ideas why the objects aren't getting persisted beyond a single JVM session? Happy to supply more information but there's so much state associated with Hibernate / JPA / HSQL that it's not clear exactly what is pertinent.

解决方案

Does anyone have any ideas why the objects aren't getting persisted beyond a single JVM session?

HSQLDB doesn't write changes immediately to disk after a commit (see "WRITE DELAY"), HSQLDB is not Durable by default (that's from where "performances" are coming from).

Either try to set the connection property shutdown=true in the connection string to get the changes written when the last connection will end.

jdbc:hsqldb:file:data/cmon;shutdown=true

If it doesn't help, try to set the WRITE DELAY to 0 (or false). If you're using HSQLDB 1.8.x, use the SQL command:

SET WRITE_DELAY 0

If you're using HSQLDB 2.0.x, you can now also use a connection property hsqldb.write_delay:

jdbc:hsqldb:file:data/cmon;hsqldb.write_delay=false

这篇关于HSQLDB和Hibernate / JPA - 不会持久化到磁盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆