Search code examples
javaplayframework-2.0playframework-2.2ebeanplayframework-2.3

Does Playframework (Ebean ORM ) support managed enties


I started working on a new project using Playframework and thought to try using it with Ebean ORM. What i am wondering now is if Play with the Ebean implementation supports managed entities and if so ..how? Take this example method from the controller:

@Transactional
public Result changePassword() {
    Long userId = Long.valueOf(session("id"));
    User user = User.find.byId(userId);
    user.setName("John Doe");
}

Is there any way to persist the changes to the database when the transaction ends? Currently what i am doing is calling user.save(). This is not much but working with JEE/JPA (and recently Dropwizard) i got used to have my entities changes persisted when the transaction ends.


Solution

  • No, I don't think Play natively supports something like auto save transaction as you want. Explicit save method is the only option.

    Ebean.save(xyz);

    General suggestion on your code, From Play 2.3.x, In your case, No need to annotate or explicitly mention the transaction, if Save is the only action on User EBean. By default each action on EBeans will be executed in separate transactions. Can specify the transaction explicitly if multiple actions need to be executed in single transaction.