java - Playframework Ebean.Save() 给出连接关闭

标签 java playframework playframework-2.2 ebean

我有一个带有简单 Address 模型的 Play Framework ,但是在调用 ebean 的 #save() 方法时,我收到以下错误。

我认为数据库配置正确(我可以毫无问题地读取模型)。 我在内存 H2 数据库上运行的单元测试运行良好。

代码:

  Address address = new Address(street, postalcode, location);
  address.save();

Play 输出:

[error] c.j.b.ConnectionHandle - Database access problem. Killing off this connection and all remaining connections in the connection pool. SQL State = HY000
[error] play - Cannot invoke the action, eventually got an error: javax.persistence.PersistenceException: java.sql.SQLException: Connection is closed!

地址类

@Entity
public class Address extends Model {
@Id
    public int id;
    public String postalcode;
    public String street;
    public String location;

    @OneToMany(cascade= CascadeType.ALL)
    public List<Estate> estates;

    public Address(String street, String postalcode, String location){
        this.postalcode = postalcode;
        this.street = street;
        this.location = location;
    }
    public Address(int id, String street, String postalcode, String location){
        this.id = id;
        this.postalcode = postalcode;
        this.street = street;
        this.location = location;
    }
    public static Finder<Integer,Address> find = new Finder<Integer, Address>(
        Integer.class, Address.class
    );
}

最佳答案

我找到了解决方案:模型的 ID 值不是由 ebean 生成的。

在我的 mysql 数据库的 id 字段上设置 auto_increment 成功了。

关于java - Playframework Ebean.Save() 给出连接关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22380496/

相关文章:

java - 为什么允许使用子类的构造函数实例化父类对象?

scala - 游戏中的 Redis 发布订阅

testing - Play 不运行测试

playframework - Reactivemongo:如何处理 Iteratee.fold 内部发生的异常

java - 无法从 View 调用 Play Framework 静态方法

java - 如何使用带有 Java 的 Selenium WebDriver (Selenium 2) 在文本框中键入内容?

java - 如何在不创建任何新文件的情况下访问 zip 文件中目录中的文件?

java - 线程中的异常 "main"java.lang.UnsatisfiedLinkError : firstdata. icvtnsclient.SslTcpClient.__ctorSslTcpClient0(Lnet/sf/jni4net/inj/IClrProxy;)V

java - Order by 子句不适用于 Play Ebean 中的字符串

java - 玩! java 。将请求参数传递给@With 注解