我正在尝试自动在数据库上创建表,并且只想导入初始数据一次。当在 hibernate.cfg.xml 上将“hibernate.hbm2ddl.auto”设置为“create”和“hibernate.hbm2ddl.import_files”时,它可以工作。但是,它每次运行都会破坏并创建数据库。我想创建表(如果不存在),为此我将参数更改为“update”,但这次“hibernate.hbm2ddl.import_files”不起作用。
org.apache.derby.jdbc.EmbeddedDriver jdbc:derby:CounterDB;create=true 5
<property name="dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<!-- Creates it only if it doesn't exist -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- import initial data to Database when it created -->
<property name="hibernate.hbm2ddl.import_files">import.sql</property>
<!-- Mapping files -->
<mapping class="com.counter.db.CameraSettings" />
<mapping class="com.db.Counts" />
最佳答案
您无需指定导入文件。 Hibernate 默认情况下会查看
WEB-INF/classes/import.sql
关于java - 首次创建数据库时,Hibernate 初始数据导入不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55419915/