O'Reilly logo

Play Framework Cookbook by Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining your own models

As soon as you have to implement business logic or objects which should be persisted, the implementation should be done in the model. Note that the default implementation of this layer is implemented in Play with the use of JPA, Hibernate, and an SQL database in the background. However, you can of course implement an arbitrary persistence layer if you want.

Getting ready

Any model you define should go into the models package, which resides in the app/models directory.

How to do it...

As in the recipes before, this was already a reference to a user entity. It is the right time to create one now. Store this in the file app/models/User.java:

package models; import javax.persistence.Entity; import play.data.validation.Email; import ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required