使用播放!框架 2.0.2,当我将 java 项目中的几个项目添加到我的 H2 测试数据库时,我在 ITEM 表中只看到一个项目。单个项目是我坚持的最后一个条目。我认为这是由于每次提交时都会重新创建数据库。因此,我想在我的 application.conf 文件中添加 JPA.ddl=update 属性。但这只是因以下错误而中断。什么
这是我的代码(在 Item.save() 方法中):
package models;
import java.math.BigDecimal;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Persistence;
@Entity
public class Item {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public int id;
public String name;
public String dev;
public String type;
public int quantity;
public BigDecimal unitPrice;
public Item() {}
public Item(String name, String dev, String type, int quantity,
BigDecimal unitPrice) {
super();
this.name = name;
this.dev = dev;
this.type = type;
this.quantity = quantity;
this.unitPrice = unitPrice;
}
/**
* Insert this new computer.
*/
public void save() {
//this.id = id;
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("defaultPersistenceUnit");
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(this);
entityManager.getTransaction().commit();
entityManager.close();
}
}
这是错误消息
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named update
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) ~[hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.
Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) ~[hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.
Final]
at play.db.jpa.JPAPlugin.onStart(JPAPlugin.java:35) ~[play_2.9.1.jar:2.0.2]
at play.api.Play$$anonfun$start$1.apply(Play.scala:60) ~[play_2.9.1.jar:2.0.2]
at play.api.Play$$anonfun$start$1.apply(Play.scala:60) ~[play_2.9.1.jar:2.0.2]
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library.jar:0.11.3]