Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is best data access options available for Play framework with Scala and PostgreSQL?

We have earlier experiences and lots of reusable code/components mostly done using Spring MVC, Hibernate, PostgreSQL database.

But recently we are planning to start a new project. We decided to use Play framework with Scala. We are new in Play framework with Scala. Thus we couldn't decided what ORM (Object-relational mapping) framework to use. Because of many reusable code, we wish to select Hibernate.

We found scary words regarding Hibernate as "JPA using Hibernate in Scala with play it is probably not the best way, and it should be considered as legacy and deprecated". We are really confused what to use?

While searching for possibilities we found Anorm and Hibernate. There could be some other framework exist, that we don't know yet.

So please suggest us what to use for Play framework with Scala and PostgreSQL?

Thanks in advance!

like image 384
masiboo Avatar asked Feb 12 '15 11:02

masiboo


People also ask

What is play framework in Scala?

Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.

Does Play support Scala 3?

Play Framework does not support Scala 3, as of August 2021.


2 Answers

If you definitely want an ORM then JPA is probably the road to go. This will force you to have mutable domain model classes etc. but maybe this is a trade off you are willing to accept. (Personally, I wouldn't)

If you are open to alternative ways to talk to a database there are a few interesting options:

  • anorm - Close to SQL but way nicer than using JDBC directly - https://playframework.com/documentation/2.3.7/ScalaAnorm
  • slick - "Functional Relational Mapping", typesafe queries - http://slick.typesafe.com
  • activate - "Software Transactional Memory" with pluggable persistence backends - http://activate-framework.org

Here is a pretty good blog post that compares different libraries: http://manuel.bernhardt.io/2014/02/04/a-quick-tour-of-relational-database-access-with-scala/

like image 122
johanandren Avatar answered Oct 03 '22 14:10

johanandren


Take a look at Skinny ORM.

http://skinny-framework.org/documentation/orm.html

http://blog.seratch.net/post/110711051753/skinny-orm-for-play-framework

Skinny ORM is not only highly inspired by Rails ActiveRecord but flexible enough because it is built upon ScalikeJDBC library which is a thin but powerful JDBC wrapper.

http://scalikejdbc.org/

like image 25
Kazuhiro Sera Avatar answered Oct 03 '22 14:10

Kazuhiro Sera