Java EE jta hibernate.hbm2ddl.import_files不起作用 [英] Java EE jta hibernate.hbm2ddl.import_files does not work

查看:90
本文介绍了Java EE jta hibernate.hbm2ddl.import_files不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在Web应用程序运行时导入sql文件.我将import.sql放入了src/main/resources/import.sql中.然后我通过添加import_files指令修改了persistence.xml:

I try to import sql file when web application runs. I placed import.sql into src/main/resources/import.sql. Then I modified my persistence.xml by adding import_files directive:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             version="2.1"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jsp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="spPU" transaction-type="JTA">
    <description>SP Persistence Unit</description>
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:jboss/datasources/SpDS</jta-data-source>

    <properties>
      <property name="hibernate.hbm2ddl.auto" value="create"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.format_sql" value="false"/>
      <property name="hibernate.hbm2ddl.import_files" value="import.sql"/>
    </properties>
  </persistence-unit>
</persistence>

但是在重新部署或重新启动服务器后,没有任何内容可以上传到数据库中. 我使用WildFly 8.1.0,Hibernate 4.3.5.Final,数据库h2database 1.3.161. 我试图从import.sql删除空白行,并将hibernate.hbm2ddl.auto更改为create-drop. 知道为什么import.sql无法在数据库中加载吗?

But after redeploy or restart server nothing to uploads in database. I use WildFly 8.1.0, Hibernate 4.3.5.Final, Database h2database 1.3.161. I tried to remove blank lines from import.sql and change hibernate.hbm2ddl.auto to create-drop. Any idea why import.sql does not load in database?

推荐答案

我也有类似情况,请检查是否:

I had similar situation, please check if:

1)您可以手动运行sql脚本(导入期间发生错误时不会显示SQL错误)

1) You can run your sql script manualy (No SQL errors are shown when error occurs during import)

2)请确保所有sql语句均单行,例如:

2) Please make sure that all sql statements are single-lined, eg:

    create table Table1{ column1, column2,etc.};

代替

    create table Table1{
     col1 ..,
     col2 ..,
    }

在使用import时,我注意到了这两个问题,希望这也能解决您的问题.

I noticed these 2 issues when using import, hope this solves your problem too.

[UPDATE]
Thx到@vsapiha有对多行sql的支持:

[UPDATE]
Thx to @vsapiha there is support for multiple lines sql:

<property name="hibernate.hbm2ddl.import_files_sql_extractor">org.hibernate.tool.hbm2ddl.M‌​ultipleLinesSqlCommandExtractor</property>

这篇关于Java EE jta hibernate.hbm2ddl.import_files不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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