我是Play的新手,在生产模式下部署应用程序时遇到问题。 我正在使用内存db开始。...播放版本为1.2.4我制作了一个带有实体的简单应用
@Entity
public class TestModel extends Model {
public String name;
}
和配置为
application.mode=prod
db=mem
%test.application.mode=prod
%test.db.url=jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
%test.jpa.ddl=create
%test.mail.smtp=mock
在控制器中只是为了测试我在做什么
public static void listBars() {
TestModel bar = new TestModel();
bar.name = "a new bar";
bar.save();
TestModel bar2 = new TestModel();
bar2.name = "a new bar2";
bar2.save();
renderJSON(TestModel.findAll());
}
真的很感激,如果我能在这方面得到一些帮助的话。代码正在开发模式下工作。
异常跟踪是
va:116)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.prepare(I
entityGenerator.java:90)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(Abstr
ctReturningDelegate.java:54)
... 24 more
9:57:31,396 WARN ~ SQL Error: 42102, SQLState: 42S02
9:57:31,397 ERROR ~ Table "TESTMODEL" not found; SQL statement:
nsert into TestModel (id, name) values (null, ?) [42102-149]
9:57:31,404 ERROR ~
69772kodd
nternal Server Error (500) for request POST /bars.json
xecution exception (In /app/controllers/Application.java around line 30)
ersistenceException occured : org.hibernate.exception.SQLGrammarException: coul
not insert: [models.TestModel]
lay.exceptions.JavaExecutionException: org.hibernate.exception.SQLGrammarExcept
on: could not insert: [models.TestModel]
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
aused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGr
mmarException: could not insert: [models.TestModel]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityMan
gerImpl.java:1214)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityMan
gerImpl.java:1147)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityMan
您需要使用类似这样的东西来自动生成表格:
jpa.ddl =创建
重要的是,不要每次都重新生成表以防止数据丢失。
参见本页: http ://www.playframework.org/documentation/1.2.4/production部分:禁用JPA自动模式更新