"editionJPA" is simple POJO object. The problem that I cannot create POJO object and transfers it to EbeanServer.save(java.lang.Object) method. EbeanServer considers that it is new record for which it is necessary to do insert, but it is necessary for me that has been made update.
I looked in source code, a choice between insert and update depends on variables which Ebean adds automatically, for example at obtaining of the object with a ebeanServer.find method. But I create POJO object passing ebeanServer, and in it there are no structures which adds ebean.
I will describe the typical scenario. I obtain the data from an web page through spring-mvc which automatically creates necessary POJO object (Edition) and makes its validation before send to DAO:
@RequestMapping(value = "/settings/editions/update/")
public String Edit(@Valid Edition edition,
BindingResult bindingResult, Model model) {
if (!hasErrors(bindingResult))
editionsService.update(edition);
jsonHelper.getModel(model, bindingResult);
return "jsonView";
}
This is EditionService.update:
public void update(Edition object) {
editionJPA.update(object);
}
And this is EditionJPA.update:
@Override
public void update(Edition object) {
String dml = "UPDATE inp_editions SET " +
"edition_enabled = :enabled, " +
"edition_color = :color, " +
"edition_title = :title, " +
"edition_stitle = :stitle, " +
"edition_description = :description, " +
"edition_updated = now()" +
"WHERE edition_uuid = :id";
SqlUpdate query = ebeanServer.createSqlUpdate(dml)
.setParameter("enabled", object.getEnabled())
.setParameter("color", object.getColor())
.setParameter("title", object.getTitle())
.setParameter("stitle", object.getStitle())
.setParameter("description", object.getDescription())
.setParameter("id", object.getUuid());
int rows = query.execute();
}
All that I want, it to reduce code EditionJPA.update to:
@Override
public void update(Edition object) {
ebeanServer.update(object);
}
As experiment I have added a update method by copy of a code of a save method, having made an unambiguous choice for update, all works fine. Only I do not wish to use own assemblage because of possible problems with compatibility.