I am trying to implement crud sort of like computer-database example using play 2.4 with ebeans. Everything works except update. When I run the computer-database example against same MariaDB and older ebeans (3.2.2), it does update just fine so does not seem to be an issue with the database. I am using MySQL connector though as found bug with Maria JDBC driver while using ebeans.
This code:
/**
* Handle the 'edit form' submission
*
* @param id Id of the user to edit
*/
public Result update(Long id) {
Form<User> userForm = form(User.class).bindFromRequest();
if(userForm.hasErrors()) {
return badRequest(editForm.render(id, userForm));
}
User userFromForm = userForm.get();
System.out.println(userForm.data());
userFromForm.update();
flash("success", "User " + userForm.get().alias + " has been updated");
return GO_HOME;
}
gives this error: [OptimisticLockException: Data has changed. updated [0] rows sql[update user set alias=?, email=?, password=?, active=?, last_update=?, user_type_id=? where id=?] bind[null]]
The entity is defined like
@Entity public class User extends Model {
private static final long serialVersionUID = 1L;
@Id
public Long id;
@Constraints.Required
public String alias;
@Constraints.Required
public String email;
@Constraints.Required
public String password;
@Constraints.Required
public char active;
@ManyToOne
public UserType userType;
@Version
@Column(columnDefinition = "timestamp default '2014-10-06 21:17:06'")
public Timestamp lastUpdate;
First, the version is not being placed in the where clause as expected. Also, the optimistic locking error is thrown.
I am connecting to MySQL. All other actions, save, delete etc. work fine. Is this broke again?
plugins look like
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.4")
// Web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-webdriver" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-js-engine" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
// Play enhancer - this automatically generates getters/setters for public fields
// and rewrites accessors of these fields to use the getters/setters. Remove this
// plugin if you prefer not to have this feature, or disable on a per project
// basis using disablePlugins(PlayEnhancer) in your build.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
// Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
// enablePlugins(SbtEbean). Note, uncommenting this line will automatically bring in
// Play enhancer, regardless of whether the line above is commented out or not.
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
//Eclipse
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")
build.sbt is
name := """mecamu-play"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean, SbtWeb, PlayEnhancer)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
k in run := true
fork in run := true
Any help would be appreciated. I would love to use bound form updates with ebean the way they worked before. Thanks so much