5 ms·
Since June, when the presentation was created, Play has gone through a few big revisions. The primary method of accessing a database is Anorm (which, if you are
by mark242 14y ago
Since June, when the presentation was created, Play has gone through a few big revisions. The primary method of accessing a database is Anorm (which, if you aren't a Hibernate fan, Anorm is a huge win) although you can also use Hibernate, or you also have the choice of using Slick, which is Typesafe's ORM (and a lot easier to use). IntelliJ 12 has better support for Play as well, and the overall performance has improved a great amount.
It's too bad that the presentation doesn't include sample Scala code for Play; imho this is the number one reason to use Play. The saveRating() controller method that they use as Play's example, which is some twenty lines of Java code, could be done in one or two lines of Scala code. Similarly, running a job in Play is essentially just spinning up an Akka actor and scheduling messages to send to it-- very very straightforward.
Play has been extremely easy to work with, especially with writing Scala code, and it's much more lightweight compared to, say, the Lift framework.
- mbell 14y agoHas play stopped using Ebean? It's my favorite Java ORM and I've never heard of Anorm.
- jaytaylor 14y agoYou can of course use whatever ORM you want, but it comes with Anorm.
- jiggy2011 14y agoCan Play 2 be made to work well with hibernate+JPA? I know many people don't like it , but I invested a fair amount of time into understanding hibernate and if I stick with the JVM I would want to be able to apply that.
- mark242 14y agoYes, it will work. There's no magic sauce about adding whichever ORM you want; just declare it as a dependency in your build file and you're ready to go.
- jiggy2011 14y agoThanks, is there anything "weird" about it though? For example: I remember in play 1.x various helper method were provided that were different from those in standard JPA including something that felt like properties in ruby. Not really a problem in practice, but required a litte trial and error when compared with the hibernate docs. However I imagine Play 2 makes use of various dynamic style programming techniques (via Scala) that might make hibernate behave in subtly different ways to what the hibernate literature might lead you to believe? I appreciate that this is an extremely hand-wavey question.
- mark242 14y agoPlay uses Ebean on the Java side of the fence. Anorm is for Scala users. Here's how to do a query for a person in Anorm: SQL("select * from person where id = {id}").on("id" -> myAgeVariable).map(row => MyPersonObject(row[String]("name"), row[Int]("age"))).toList ...returns you a list of MyPersonObjects. No need for JPA bindings or any other annotations. Based on type safety, you must have the method MyPersonObject.apply(name: String, age: Int) or else the compiler will error. It's a great way of catching SQL funkiness inside your IDE.
- alexatkeplar 14y agoYech, embedding raw SQL strings in a typesafe, compiled language like Scala is so full of fail it's not funny. Hopefully they'll switch out Anorm for Slick (which is also a Typesafe project - http://slick.typesafe.com/ http://slick.typesafe.com/) soon.
- codewright 14y agoEbean vs. Anorm vs. Slick is a good example of why I don't like using full-stack frameworks. When I use minimalist web frameworks, I get to use best-of-class libraries across the board, not make decisions based on damage control. Examples of minimalist web frameworks: Sinatra, Flask, Scalatra, Ring/Compojure
- tommi 14y agoThere's nothing blocking from using Slick or any ORM in Play.
- alexatkeplar 14y agoYep, I do like the Ring/Compojure philosophy. Actually we just open-sourced a pixel server based on Ring/Compojure yesterday (https://github.com/snowplow/snowplow/tree/master/2-collectors/clojure-collector https://github.com/snowplow/snowplow/tree/master/2-collector...)
- eeperson 14y agoAgreed, about about Ebean being the nicest Java ORM. Ebean's lack of a stateful session seems much less maddening than Hibernate. I wonder why it isn't used more.
- jsoalevel 14y agoWhat do you think about mybatis instead of hibernate ? Ebean looks interesting but it seems me that there is very small community, some documentation are from year 2009(it seems me litle bit old).