【问题标题】:Playframework Ebean.Save() gives Connection ClosedPlayframework Ebean.Save() 提供连接关闭
【发布时间】:2014-03-13 13:43:13
【问题描述】:

我有一个带有简单 Address 模型的游戏框架,但在调用 ebean 的 #save() 方法时出现以下错误。

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

代码:

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

播放输出:

[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
    );
}

【问题讨论】:

    标签: java playframework playframework-2.2 ebean


    【解决方案1】:

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

    在我的 mysql 数据库的 id 字段上设置 auto_increment 有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 1970-01-01
      • 2019-07-27
      • 1970-01-01
      • 2010-09-13
      • 1970-01-01
      相关资源
      最近更新 更多