Hoping for some high-level advice on Hibernate vs. Slick and current Slick capabilities.
We are currently looking at a revised technology stack for the next generation of our
application framework. Moving from Java to Scala seems to be almost a certainty,
however, not quite as certain on the persistence approach. Current application framework built approximately 10 years ago in Java includes a
custom ORM that has served us well. When looking at the new technology stack the
first option was obviously Hibernate which based on a very basic proof of concept
seems to be viable. And research seems to indicate that for the most part, a
Hibernate based solution would play reasonably well with Scala. We then came across Slick which would appear to be much better integrated with
Scala (obviously) and technically a solution which can only continue to get better. Unfortunately my experience with Scala is less than a few weeks and similarly for
Hibernate; only a few weeks including the architecture proof of concept. Slick
experience is only a few days and I'm continually looking for real world examples,
particularly some more CRUD oriented code rather than looking at different variants
on more complicated queries. For example, our custom ORM framework understands relationships between objects e.g.,
person has a home address and work address, addresses have suburbs, etc. So when you
call "save" on a person object the executed SQL manages the multiple tables, foreign
keys etc. It also handles only updating changed columns. It appears that Hibernate
does the same but haven't played enough with it yet to be sure. Slick on the other hand appears to take care of database portability, mapping complex
queries directly to Scala collections etc. However, I can't see that it currently
supplies much at the higher level of automatically performing all the updates/inserts
necessary for example when calling "person.save()"? What about only updating changed
columns? Would the application programmer / library developer have to write most of
this code? Is this a fair assessment or have I missed some of the current functionality?
Unfortunately my rudimentary understanding of Scala at this point is hindering
my understanding of what Slick is currently capable of. Based on my current understanding I still look like using Slick for the persistence
layer. Hibernate may well be a closer fit to our current ORM but over time it's not
going to integrate any better. Slick will have a considerably longer learning curve,
but the Scala we're going to have to learn anyway. Slick will integrate better and
over time will catch up in terms of functionality. There's also the future back-end
support for NoSQL and other data sources such as web services. Worst case we're back
to a custom ORM but built on top of Slick rather than Java which will offer us better
ongoing integration in the long term.
As you can probably tell I'm trying to convince myself that Slick is the way to go :-)
even though probably much more work in the short term. Any comments / guidance would
be much appreciated. I'd be particularly keen to be pointed at some examples of a CRUD
type framework e.g., support for code similar to
val person = Persons.byId(1234).firstval suburb = Suburbs.byName("suburbname").firstval address = Address("Street Line 1",suburb)person.homeAddess = addressperson.save
The "person.save" should do an insert into address table followed by update of only the
home_address column in the person table.
Apparently database portability is not a goal of the Slick project. I wish it was.Mike
You may want to look at Activate: http://activate-framework.org/
val person = Persons.byId(1234).firstval suburb = Suburbs.byName("suburbname").firstval address = Address("Street Line 1",suburb)person.homeAddess = addressperson.save
db.withTransaction{ implicit session: Session =>
val suburb_id = Suburbs.filter(_.name === “suburbname”).map(_.id).first
val address_id = Addresses.insert(Address(None,“Street Line 1”,suburb_id))
Persons.filter(_.name === 1234).map(_.home_address_id).update(address_id)
} // <- save happens here--
---
You received this message because you are subscribed to a topic in the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scalaquery/aOyzJ30Ja_0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scalaquery+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Regarding serialization:
As mentioned, I suggest looking into http://lampwww.epfl.ch/~hmiller/pickling/. Imho, it improves the state of the art considerably.
Concerning query generation:
I agree that a lot of work is still needed, but I think the right people are aware of it (and in charge).
I'm not a huge user of Slick, but it has come a long way since ScalaQuery.