如何使用javax.persistence.sql-load-script-source? [英] How to work with javax.persistence.sql-load-script-source?

查看:83
本文介绍了如何使用javax.persistence.sql-load-script-source?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动将数据插入到MySQL表中.因此,我尝试在我的 persistence.xml 中使用JPA属性"javax.persistence.sql-load-script-source":

I want to automatically insert data into my MySQL tables. Therefore I try to use the JPA property "javax.persistence.sql-load-script-source" in my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="my-PU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/coding</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
      <property name="javax.persistence.ddl-drop-script-source" value="drop.sql" />
      <property name="javax.persistence.sql-load-script-source" value="insert.sql"/>
    </properties>
  </persistence-unit>
</persistence>

SQL脚本(drop.sql和insert.sql)存储在"src/main/resources"中,并包含SQL命令.不幸的是,这些命令没有执行.我忘了财产吗?

The SQL scripts (drop.sql & insert.sql) are store in "src/main/resources" and include SQL commands. Unfortunately, these commands are not executed. Did I forget a property?

推荐答案

您正在使用哪个版本的EclipseLink?这些属性是JPA 2.1的一部分,因此您必须使用EclipseLink 2.5版本(尚未发布).

What version of EclipseLink are you using? These properties are part of JPA 2.1, so you must be using the EclipseLink 2.5 version (not yet released).

启用最佳登录功能以查看是否发生任何错误.

Enable logging on finest to see if any errors are occurring.

这篇关于如何使用javax.persistence.sql-load-script-source?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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