Migrate step by step from Java/Ebean to Scala

62 views
Skip to first unread message

Johan Dahlberg

unread,
Jan 28, 2015, 3:11:29 PM1/28/15
to play-fr...@googlegroups.com
In a project we have at my work we use Play 2.3.7 with the Java API:s and Ebean. But I'm a little bit eager to start going towards Scala.

How would a good long term plan to migrate to Scala look? The important part is that I need to be able to make the change step by step in a longer term. I won't be able to migrate everything in a shorter term so I need to be able to use Ebean in my old code. Is there any good way to be able to use the same data model and models with Scala?

James Roper

unread,
Jan 28, 2015, 9:49:52 PM1/28/15
to play-framework
Hi Johan,

I think sticking with using Ebean is a sensible thing to do, then you can, for example, migrate your actions, still using the ebean plugin and ebean models.

Cheers,

James

On Thu, Jan 29, 2015 at 7:11 AM, Johan Dahlberg <jo...@dahlberg.co> wrote:
In a project we have at my work we use Play 2.3.7 with the Java API:s and Ebean. But I'm a little bit eager to start going towards Scala.

How would a good long term plan to migrate to Scala look? The important part is that I need to be able to make the change step by step in a longer term. I won't be able to migrate everything in a shorter term so I need to be able to use Ebean in my old code. Is there any good way to be able to use the same data model and models with Scala?

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
James Roper
Software Engineer

Typesafe – Build reactive apps!
Twitter: @jroper

Johan Dahlberg

unread,
Jan 29, 2015, 2:17:24 AM1/29/15
to play-fr...@googlegroups.com
How would I use Ebean in Scala? Do I need to do something different to be able to use Ebean in Scala?

/Johan

Alex Loskutov

unread,
Jan 29, 2015, 4:27:40 AM1/29/15
to play-fr...@googlegroups.com
When I used Ebean from Scala I have some troubles with  fetching entities' foreign keys 

After some brainf*cking I began to use Squeryl

четверг, 29 января 2015 г., 11:17:24 UTC+4 пользователь Johan Dahlberg написал:

James Roper

unread,
Jan 29, 2015, 7:33:05 PM1/29/15
to play-framework
Hi Johan,

At the end of the day, whether you use Java or Scala, it's all just bytecode - both Scala and Java compiles to the same classes, methods, fields in byte code, which is why they are so interoperable, you can mix and match Java and Scala source code and libraries as much as you want, and generally everything plays really well.  So you use ebean from Scala the same way that you use ebean from Java - just use it.

That said, there are a few things you need to be aware of, some features of Scala, when compiled to bytecode, are a bit weird to use from Java.  This includes Scala lambdas, by name parameters, accessors, objects, and a number of other things.  These things could confuse ebean's reflection.  I would recommend keeping your models themselves in Java, but then using them from Scala.  Also a helpful thing, when talking to Java code from Scala, if the Java code uses Java collections (eg java.util.List), it's often very convenient to import the collection conversions:

import scala.collection.JavaConversions._

This provides implicit conversions so you can treat Java collections as if they were Scala collections (eg, you can map/flatMap/foreach etc etc), as well as pass Scala collections to methods that accept Java collections and vice versa.

Regards,

James

Johan Dahlberg

unread,
Jan 30, 2015, 1:44:43 AM1/30/15
to play-fr...@googlegroups.com
Nice, so I only import the Java conversions and then they will be converted automatically?

Thanks for the help, I will try to start working a bit in Scala then.

/Johan

--
You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/JJL5MBAn0Ds/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages