1 回答
TA贡献2003条经验 获得超2个赞
只需像下面这样更改我的 persistence.xml 内容,然后在删除文件之前关闭 EntityManagerFactory。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="NewPersistenceUnit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>model.MycardsEntity</class>
<class>model.PeymentsEntity</class>
<class>model.WorkersEntity</class>
<class>model.YourcardsEntity</class>
<class>model.LoginEntity</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:h2:file:./data/mydata;DB_CLOSE_ON_EXIT=FALSE;FILE_LOCK=NO"/>
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
<property name="hibernate.connection.username" value=""/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
现在可以使用以下方式删除文件:
DeleteDbFiles.execute("./data", "mydb", false);
添加回答
举报