Hi,
With Play 1.2
In documentation it's no write that a call to merge() will save new
entity.
http://www.playframework.org/documentation/1.2/jpa#save
Here is the test case :
package models.essais;
import javax.persistence.*;
import play.data.validation.*;
import play.db.jpa.GenericModel;
@Entity
public class Person extends GenericModel {
@Id
@GeneratedValue
public int id ;
@Required
@MinSize(2)
public String name ;
}
package controllers;
import models.essais.Person;
import play.Logger;
import play.mvc.*;
public class Essais02 extends Controller {
public static void index() {
Logger.debug("Person count %d", Person.count());
Person p = new Person();
p.name = "blabla";
p.merge();
render("Essais/essais02.html");
}
}
import play.*;
import play.jobs.*;
@OnApplicationStart
public class Bootstrap extends Job {
@Override
public void doJob() {
Fixtures.loadModels("data-essais.yml");
}
}
And the "data-essais.yml":
essais.Person(p1):
name: Foo
Refresh the page Essais02 and you will see the Person.count()
incrementing.
And this "bug?" is only for just created entity, for existing entity
the merge() works has expected: no change in the db.
The second test case (add this method to controller Essais02):
public static void test2() {
Logger.debug("Person count %d", Person.count());
Person p = Person.all().first();
Logger.debug("first Person name: %s",
p.name);
p.name = "blabla";
p.merge();
render("Essais/essais02.html");
}
You can see that for the existed entity the "
p.name" never change, the
count never increase. That's what expected.
Cheers
Cyrille.