0

因为我的 persistence.xml 使用drop-and-create-tables

<?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="USENETPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>net.bounceme.dur.usenet.model.NewsgroupsArticles</class>
    <class>net.bounceme.dur.usenet.model.Article</class>
    <class>net.bounceme.dur.usenet.model.Newsgroup</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/nntp"/>
      <property name="javax.persistence.jdbc.password" value="password"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="java"/>
      <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

我的触发器每次运行都会被删除。我可以将触发器放在哪里,以免它们被移除?

4

1 回答 1

1

您应该使用SessionCustomizer. 在您的持久性属性中,您应该插入一个指向您的SessionCustomizer实现的属性。

properties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, MySessionCustomizer.class.getName());

或者

<property name="eclipselink.session.customizer" value="foo.bar.MySessionCustomizer" />

在这个会话定制器中,您可以加载您的触发代码并让它执行:

unitOfWork.executeNonSelectingSQL(sql);

您可以在此处找到有关此主题的详细说明

于 2012-07-29T11:00:27.353 回答