0

我有一个带有 HSQL 数据库的程序。但是,如果我运行该程序,它应该创建一些订单和东西。但是当程序被正确关闭时,它不会将日期保存到“DB.script”中,我必须第二次运行它才能看到“DB.script”中的变化。有人知道这个问题的解决方案吗?

这是我关闭数据库连接的方法:

public void closeAll(Object name){
    session = sf.getCurrentSession();
    transaction = session.beginTransaction();
    session.persist(name);
    session.flush();
    session.saveOrUpdate(name);
    transaction.commit();
    org.hsqldb.DatabaseManager.closeDatabases(0);
    System.out.println("[Info] Connection Closed");
}

这里是我的 HSQL DB.script:

SET DATABASE UNIQUE NAME HSQLDB3D7E03560E
SET DATABASE GC 0
SET DATABASE DEFAULT RESULT MEMORY ROWS 0
SET DATABASE EVENT LOG LEVEL 0
SET DATABASE SQL NAMES FALSE
SET DATABASE SQL REGULAR NAMES TRUE
SET DATABASE SQL REFERENCES FALSE
SET DATABASE SQL SIZE TRUE
SET DATABASE SQL TYPES FALSE
SET DATABASE SQL TDC DELETE TRUE
SET DATABASE SQL TDC UPDATE TRUE
SET DATABASE SQL TRANSLATE TTI TYPES TRUE
SET DATABASE SQL CONCAT NULLS TRUE
SET DATABASE SQL NULLS FIRST TRUE
SET DATABASE SQL UNIQUE NULLS TRUE
SET DATABASE SQL CONVERT TRUNCATE TRUE
SET DATABASE SQL AVG SCALE 0
SET DATABASE SQL DOUBLE NAN TRUE
SET DATABASE SQL LONGVAR IS LOB FALSE
SET DATABASE TRANSACTION CONTROL LOCKS
SET DATABASE DEFAULT ISOLATION LEVEL READ COMMITTED
SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE
SET DATABASE TEXT TABLE DEFAULTS ''
SET FILES WRITE DELAY 0
SET FILES BACKUP INCREMENT TRUE
SET FILES CACHE SIZE 10000
SET FILES CACHE ROWS 50000
SET FILES SCALE 32
SET FILES LOB SCALE 32
SET FILES DEFRAG 0
SET FILES NIO TRUE
SET FILES NIO SIZE 256
SET FILES LOG TRUE
SET FILES LOG SIZE 50
CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e'
ALTER USER SA SET LOCAL TRUE
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
SET SCHEMA PUBLIC
CREATE SEQUENCE PUBLIC.SEQU AS INTEGER START WITH 10
CREATE MEMORY TABLE PUBLIC.ROLLE(ID INTEGER NOT NULL PRIMARY KEY,ADMIN BOOLEAN,NAME VARCHAR(20))
CREATE MEMORY TABLE PUBLIC.SORTEBEST(FKKAFFEESORTEN INTEGER NOT NULL,FKBESTELLUNG INTEGER,ANZAHL INTEGER)
CREATE MEMORY TABLE PUBLIC.KAFFEESORTE(ID INTEGER NOT NULL PRIMARY KEY,NAME CHARACTER(20),PREIS DOUBLE,TYP CHARACTER(20))
CREATE MEMORY TABLE PUBLIC.USER(NAME CHARACTER(20),EMAIL VARCHAR(40),FK_ROLLE INTEGER,LOGONID CHARACTER(8) PRIMARY KEY,CONSTRAINT FK_USER_ROLLE FOREIGN KEY(FK_ROLLE) REFERENCES PUBLIC.ROLLE(ID))
CREATE MEMORY TABLE PUBLIC.BESTELLUNG(ID INTEGER GENERATED BY DEFAULT AS SEQUENCE PUBLIC.SEQU NOT NULL PRIMARY KEY,FKUSER CHARACTER(8),BESTELLT BOOLEAN,DATUM DATE,CONSTRAINT FK_USER_BEZIEHUNG FOREIGN KEY(FKUSER) REFERENCES PUBLIC.USER(LOGONID))
ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 0
ALTER SEQUENCE PUBLIC.SEQU RESTART WITH 5
SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.YES_OR_NO TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CARDINAL_NUMBER TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC
GRANT DBA TO SA
SET SCHEMA SYSTEM_LOBS
INSERT INTO BLOCKS VALUES(0,2147483647,0)
SET SCHEMA PUBLIC
INSERT INTO ROLLE VALUES(1,FALSE,'NORMALER_USER')
INSERT INTO ROLLE VALUES(2,TRUE,'ADMINISTRATOR')
INSERT INTO SORTEBEST VALUES(1,0,0)
INSERT INTO SORTEBEST VALUES(2,0,0)
INSERT INTO SORTEBEST VALUES(3,0,0)
INSERT INTO SORTEBEST VALUES(4,0,0)
INSERT INTO SORTEBEST VALUES(5,0,0)
INSERT INTO SORTEBEST VALUES(6,0,0)
INSERT INTO SORTEBEST VALUES(7,0,0)
INSERT INTO SORTEBEST VALUES(8,0,0)
INSERT INTO SORTEBEST VALUES(9,0,0)
INSERT INTO SORTEBEST VALUES(10,0,0)
INSERT INTO SORTEBEST VALUES(11,0,0)
INSERT INTO SORTEBEST VALUES(12,0,0)
INSERT INTO SORTEBEST VALUES(13,0,0)
INSERT INTO SORTEBEST VALUES(14,0,0)
INSERT INTO SORTEBEST VALUES(15,0,0)
INSERT INTO SORTEBEST VALUES(1,4,0)
INSERT INTO SORTEBEST VALUES(2,4,0)
INSERT INTO SORTEBEST VALUES(3,4,0)
INSERT INTO SORTEBEST VALUES(4,4,0)
INSERT INTO SORTEBEST VALUES(5,4,0)
INSERT INTO SORTEBEST VALUES(6,4,0)
INSERT INTO SORTEBEST VALUES(7,4,0)
INSERT INTO SORTEBEST VALUES(8,4,0)
INSERT INTO SORTEBEST VALUES(9,4,0)
INSERT INTO SORTEBEST VALUES(10,4,0)
INSERT INTO SORTEBEST VALUES(11,4,0)
INSERT INTO SORTEBEST VALUES(12,4,0)
INSERT INTO SORTEBEST VALUES(13,4,0)
INSERT INTO SORTEBEST VALUES(14,4,0)
INSERT INTO SORTEBEST VALUES(15,4,0)
INSERT INTO KAFFEESORTE VALUES(1,'Ristretto           ',0.5E0,'Espresso            ')
INSERT INTO KAFFEESORTE VALUES(2,'Arpeggio            ',0.5E0,'Espresso            ')
INSERT INTO KAFFEESORTE VALUES(3,'Roma                ',0.5E0,'Espresso            ')
INSERT INTO KAFFEESORTE VALUES(4,'Livanto             ',0.5E0,'Espresso            ')
INSERT INTO KAFFEESORTE VALUES(5,'Capriccio           ',0.5E0,'Espresso            ')
INSERT INTO KAFFEESORTE VALUES(6,'Volluto             ',0.5E0,'Espresso            ')
INSERT INTO KAFFEESORTE VALUES(7,'Cosi                ',0.5E0,'Espresso            ')
INSERT INTO KAFFEESORTE VALUES(8,'Decaffeinato Intenso',0.5E0,'Decaffeinato        ')
INSERT INTO KAFFEESORTE VALUES(9,'Decaffeinato        ',0.5E0,'Decaffeinato        ')
INSERT INTO KAFFEESORTE VALUES(10,'Decaffeinato Lungo  ',0.52E0,'Decaffeinato        ')
INSERT INTO KAFFEESORTE VALUES(11,'Fortissio Lungo     ',0.52E0,'Lungo               ')
INSERT INTO KAFFEESORTE VALUES(12,'Vivalto Lungo       ',0.52E0,'Lungo               ')
INSERT INTO KAFFEESORTE VALUES(13,'Linizio Lungo       ',0.52E0,'Lungo               ')
INSERT INTO KAFFEESORTE VALUES(14,'Indriya from India  ',0.57E0,'Pure Orgin          ')
INSERT INTO KAFFEESORTE VALUES(15,'Rosabaya de Colombia',0.57E0,'Pure Orgin          ')
INSERT INTO USER VALUES('Jonas            ','test@hotmail.com',2,'324     ')
INSERT INTO BESTELLUNG VALUES(0,'234    ',TRUE,'2013-04-26')
INSERT INTO BESTELLUNG VALUES(1,'234    ',TRUE,'2013-04-29')
INSERT INTO BESTELLUNG VALUES(2,'234    ',TRUE,'2013-04-29')
INSERT INTO BESTELLUNG VALUES(3,'234    ',TRUE,'2013-04-29')
INSERT INTO BESTELLUNG VALUES(4,'234    ',TRUE,'2013-04-29')
4

1 回答 1

0

在 HSQL手册中找到了答案:

使用 CREATE TABLE 命令时,内存表是默认类型。它们的数据完全保存在内存中,但对其结构或内容的任何更改都会写入 .script 文件。下次打开数据库时读取脚本文件,并重新创建 MEMORY 表及其所有内容。因此,与 TEMP 表不同,默认的 MEMORY 表是持久的。

于 2013-04-29T12:04:02.290 回答