Back

Play Slick with Oracle

Introduction

user

Piotr Limanowski

A señor software dev based in Gdansk, PL. Been doing scalable web products, with variety of languages (see above for the most recent), since early 2000s. Constatly working on simplyfing things. I write, talk and ship code. Aside from that I'm el modo holy brujito and a future hoverboard owner.


Featured

Play Slick with Oracle

Posted by Piotr Limanowski on .

Working with Oracle database never is a pleasure. Right on from the environment setup till the very first CRUD operations. Yet often times we're forced to do so. As I haven't found one, here's a quick guide on how to integrate Oracle into Play/Slick app.

Dependencies

Oracle is supported via a closed-source slick-extensions plugin from Typesafe that wraps JDBC driver. Pull it into your build by adding slick-extensions library and appropriate version of play-slick module to your build:

libraryDependencies ++= "com.typesafe.slick" %% "slick-extensions" % "2.0.0" ::
                        "com.typesafe.play" %% "play-slick" % "0.8.0" ::
                        Nil

Configuration

In Play application.conf file set your database connection settings to (whereas default is db name):

db.default.slickdriver=com.typesafe.slick.driver.oracle.OracleDriver  
db.default.driver=oracle.jdbc.OracleDriver  
db.default.url="jdbc:oracle:thin:@host:1521:sid"  
db.default.user=username  
db.default.password="password"  

Usage

In your model classes import com.typesafe.slick.driver.oracle.OracleDriver.simple._ and you’re good to go.

Known Issues

A known issue with Oracle database is that whenever passing an empty value or nothing with an AutoInc index the db complains. To solve the issue you must provide the value which effectively means no AutoInc at all. Thus, I employed a simple solution of creating a spin-off data object without the id (and in most cases it is also my domain object as I usually don’t need ids) and then map it into the DB-compatible one. For the last task you might use a type class (I would not recommend using implicit conversion).