Book Image

Scala for Java Developers

By : Thomas Alexandre
Book Image

Scala for Java Developers

By: Thomas Alexandre

Overview of this book

Table of Contents (19 chapters)
Scala for Java Developers
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Dealing with persistence in the Play Framework


The Play Framework can be run with any sort of ORM, whether it is Java based such as JPA or Scala specific. There are related-but-separate Java and Scala flavors of the framework. As described in the Play documentation, the Java version uses Ebean as its ORM, whereas the Scala alternative does not use ORM but runs with Anorm, a Scala-ish abstraction layer on top of JDBC that interacts with a database using plain SQL.

A simple example using Anorm

To illustrate the usage of Anorm, we are going to make a small Play example that connects to the existing CustomerDB database from the NetBeans distribution that we have used in the previous section and introduced in Chapter 2, Code Integration.

The most straightforward way to start is to create a default Play Scala project from a terminal window by entering the following command:

> play new anormsample

Once created and imported into Eclipse (after creating Eclipse-related files once again using the...