--
---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ebean/e776d0b1-d3df-41c9-a12e-68fb810c7dd2n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ebean/3857476b-3418-4d9c-b6d3-72242d50d16an%40googlegroups.com.
public class TestStatelessUpdate extends TransactionalTestCase {
@Test
public void test() {
EBasic e = new EBasic();
e.setName("something");
e.setStatus(Status.NEW);
e.setDescription("wow");
DB.save(e);
// confirm saved as expected
EBasic original = DB.find(EBasic.class, e.getId());
assertEquals(e.getId(), original.getId());
assertEquals(e.getName(), original.getName());
assertEquals(e.getStatus(), original.getStatus());
assertEquals(e.getDescription(), original.getDescription());
// test updating just the name
EBasic updateNameOnly = new EBasic();
updateNameOnly.setId(e.getId());
updateNameOnly.setName("updateNameOnly");
LoggedSql.start();
DB.update(updateNameOnly);
List<String> sql = LoggedSql.collect();
original = DB.find(EBasic.class, e.getId());
assertEquals(e.getStatus(), original.getStatus());
assertEquals(e.getDescription(), original.getDescription());
assertEquals(updateNameOnly.getName(), original.getName());
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update e_basic set name=? where id=?; -- bind(updateNameOnly");
LoggedSql.collect();
// test setting null
EBasic updateWithNull = new EBasic();
updateWithNull.setId(e.getId());
updateWithNull.setName("updateWithNull");
updateWithNull.setDescription(null);
DB.update(updateWithNull);
sql = LoggedSql.stop();
// name and description changed (using null)
original = DB.find(EBasic.class, e.getId());
assertEquals(e.getStatus(), original.getStatus());
assertEquals(updateWithNull.getName(), original.getName());
assertNull(original.getDescription());
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("update e_basic set name=?, description=? where id=?; -- bind(updateWithNull,null,");
}
To view this discussion on the web visit https://groups.google.com/d/msgid/ebean/6b094a6f-6a5a-4a92-bffb-455d41b920f0n%40googlegroups.com.
> The entity beans are enhanced and Ebean knows which fields have been "set" so the properties included in the update are the fields that have been set.
I'll got it finally. Thanks for clarification. But we haven't setters on our models for immutability purposes so we can't use this feature. Methods SomeModel.builder().build() and someModel.toBuilder().build() create new instances by constructor so there is no use of setters at all in whole project.
> and pushed a fix to master branch for that
Thank you very much for fix, Rob. Is there maven repository where last SNAPSHOT version of Ebean can be downloaded? Or it must be built locally by cloning repository?
> create new instances by constructor so there is no use of setters at all in whole project.
Ah, I think that will still work in that for the bytecode enhancement it actually is replacing the appropriate PUTFIELD calls with the internal setter method and it does this on constructor code (not just setter/mutator methods). So I think you will find this still works in this case of just using constructors.
> where last SNAPSHOT version of Ebean can be downloaded? Or it must be built locally by cloning repository?
To view this discussion on the web visit https://groups.google.com/d/msgid/ebean/cb389897-50e1-4eb0-840d-2baf1cc14b8fn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ebean/e5ba1f58-8fbe-4b7c-8d12-82b60c6ea181n%40googlegroups.com.