我正在尝试在Play Framework 2.2.2中实现Envers。我阅读了很多方法,但它不起作用。当我对使用@Audited注释的实体进行一些更改(保存或更新)时,数据库架构中没有任何更改。
我的更改:
build.sbt
name := "labor"
version := "1.0-SNAPSHOT"
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
javaJpa, // <-- added
"mysql" % "mysql-connector-java" % "5.1.30",
"org.hibernate" % "hibernate-envers" % "4.3.5.Final",
"org.hibernate" % "hibernate-entitymanager" % "4.3.5.Final", // <-- added
cache
)
play.Project.playJavaSettings
application.conf
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/****?characterEncoding=UTF-8"
db.default.user=****
db.default.pass=****
db.default.jndiName=DefaultDS
的persistence.xml
<persistence 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"
version="2.0">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
</properties>
</persistence-unit>
</persistence>
Supplier.java
package models;
import javax.persistence.*;
import org.hibernate.envers.Audited;
import play.api.libs.iteratee.Cont;
import play.data.validation.Constraints;
import play.db.ebean.Model;
@Entity
@Audited
public class Supplier extends Model{
@Id
public Long id;
@Constraints.Required
@Audited
public String companyName;
@OneToOne(cascade = CascadeType.ALL)
public Contact contact;
@OneToOne(cascade = CascadeType.ALL)
public Address address;
public Supplier(String companyName){
this.companyName = companyName;
}
// -- Queries
public static Model.Finder<Long,Supplier> find = new Model.Finder<Long,Supplier>(Long.class, Supplier.class);
}
Suppliers.java
package controllers;
import models.Country;
import models.Supplier;
import play.mvc.*;
import play.data.*;
import static play.data.Form.*;
import views.html.suppliers.*;
public class Suppliers extends Controller {
public static Result index() {
return ok(index.render(Supplier.find.all()));
}
@Transactional
public static Result addSupplier() {
Form<Supplier> formSupplier = form(Supplier.class).bindFromRequest();
System.out.print(formSupplier.data());
if(formSupplier.hasErrors()){
return badRequest(add.render(formSupplier));
}
Supplier supplier = formSupplier.get();
supplier.address.save();
supplier.contact.save();
supplier.save();
return redirect(routes.Suppliers.index());
}
@Transactional
public static Result editSupplier(Long supplierId) {...}
}
如果有人能帮助我,我将非常感激。
祝你好运, couda
//编辑(1):
但它仍然无效。首先,我收到了关于@Audited的错误,该错误在被引用的类(地址/联系人)中丢失了。在确定应用程序正常工作之后,除了在编辑前端中的实体后没有添加更多表。
该配置有什么问题?