我想自动将数据插入到我的 MySQL 表中。因此,我尝试在我的persistence.xml中使用 JPA 属性“javax.persistence.sql-load-script-source” :
<?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 命令。不幸的是,这些命令没有被执行。我忘记了财产吗?