【发布时间】:2013-04-08 12:19:36
【问题描述】:
我的播放框架配置有一个问题,当我插入一个新的Notification 时,我收到了错误。我不知道为什么会出现这个错误。因为我扩展了Model 类,所以 Play 必须为每一行生成一个新的 ID。
如果你能告诉我问题出在哪里,或者有其他更好的方法,也许如果我扩展 GenericModel 并执行如下注释的代码:
// @Id
// @GeneratedValue(strategy = GenerationType.AUTO)
// public long id;
但如果我这样做,我必须如何插入新行?
非常感谢!!!!
发现错误:
PersistenceException 发生:
org.hibernate.HibernateException:数据库未返回本机生成的标识值
这是/app/controllers/WSConfiguracion.java:
if (cliente.valorBateria < filasConfiguracionClientes.get(i).limiteBateria) {
if (!estadoNotificacion.hayNotiBateria) {
// code below generated the error
Notificacion notificacion = new Notificacion(
filasConfiguracionClientes.get(i).imeiadmin,imei, "bateria baja"
).save();
estadoNotificacion.hayNotiBateria = true;
//notificacion.save();
estadoNotificacion.save();
renderText("NOTIFICA BATERIA");
}
} else {
...
}
这是我的模型。
package models;
import javax.persistence.Entity;
import play.db.jpa.Model;
@Entity
public class Notificacion extends Model {
//@Id
//@GeneratedValue(strategy = GenerationType.AUTO)
//public long id;
//@Id
public long imeiadmin;
//@Id
public long imeiclient;
public String detalleNotificacion;
public Notificacion(long imeiadmin, long imeiclient,String detalleNotificacion) {
this.imeiadmin = imeiadmin;
this.imeiclient = imeiclient;
this.detalleNotificacion = detalleNotificacion;
}
}
【问题讨论】:
-
你能重新格式化一下,让它可读吗?例如删除行号。
标签: java web-services jpa playframework playframework-1.x