如何在Hibernate,MySQL应用程序中使用import.sql文件将默认数据插入到表中 [英] How to insert default data into table using import.sql file in Hibernate, MySQL Application
问题描述
我正在开发一个使用Spring MVC(3.1版),Hibernate(3.5版)和MySQL的应用程序。在这个应用程序中,我每次运行应用程序时都会创建一个数据库模式。我想用import.sql脚本文件在一些表格中插入一些默认数据。为此,我在根中创建了import.sql脚本,并在hibernate中使用以下语句。 CFG。 xml文件。
< property name =hibernate.hbm2ddl.auto> create< / property>
< property name =hibernate.hbm2ddl.import_files> import.sql< / property>
< property name =connection.autocommit> true< / property>
但是我没有成功将默认数据插入到表中。
请指导我。
Spring必须知道从哪里找到您的文件。 b
$ b
如果您使用的是maven,有几种方法可以这样做。
可以使用classpath:/import.sql并将put你的文件在src / test / resources或者src / main / resources中,这取决于你是否仅仅需要这个测试。
I am developing an application using Spring MVC (version 3.1), Hibernate (Version 3.5) and MySQL. In this application, I am creating a database schema each time when the application runs. I want to insert some default data into a few tables using import.sql script file. For this I have created import.sql script in the root and using the following statements in hibernate. cfg. xml file.
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.hbm2ddl.import_files">import.sql</property>
<property name="connection.autocommit">true</property>
But I am not getting success to insert default data into tables.
Please guide me.
Spring must know where to find your file.
If you are using maven, there are several way of doing so.
you can use classpath:/import.sql and put your file in src/test/resources or src/main/resources, depending if you need this for test only or not.
这篇关于如何在Hibernate,MySQL应用程序中使用import.sql文件将默认数据插入到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!