I'm about to write a Scala command-line application that relies on a MySQL database. I've been looking around for ORMs, and am having trouble finding one that will work well.
The Lift ORM looks nice, but I'm not sure it can be decoupled from the entire Lift web framework. ActiveObjects also looks OK, but the author says that it may not work well with Scala.
I'm not coming to Scala from Java, so I don't know all the options. Has anyone used an ORM with Scala, and if so, what did you use and how well did it work?
So, do you need an ORM? If you have any more or less complex project and you work with a relational database, then yes, definitely. Big ORMs seem "bloated" not because they are bad tools, but rather because the underlying problem of object-relational mapping is hard.
Yes, ORM will slow down your application. By how much depends on how far the abstraction goes, how well your object model maps to the database, and other factors. The question should be, are you willing to spend more developer time and use straight data access or trade less dev time for slower runtime performance.
According to the official definition, it is “A layer of Mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself.” That means that there is a special layer that separates in-memory objects from the database and its main responsibility is to transfer data ...
Object-relational mapping (ORM) is a layer that converts our data between Database and object-oriented entities using object-oriented programming (OOP) language. There are several ORM tools available in the market. Given below are some of the most commonly used tools required to build applications and they are
To measure the performance, Software developers will have to practically check the performance of different ORMs. Users can download the sample project and required database script files from here. Then later start with setting up a Database environment. 1. Environment Setup – Database
So the whole methodology followed by ORMs is dependent on the object-oriented paradigm. ORMs generate objects which map to tables in the database virtually. Once these objects are up, then coders can easily work to retrieve, manipulate or delete any field from the table without paying much attention to language specifically.
Some common ORMs and related OOPs language are: 1 Hibernate: JAVA 2 Django ORM: Django 3 SQL Alchemy: Flask 4 Microsoft Entity Framework: .NET framework 5 Dapper ORM: C# 6 JAVA Persistence API: JAVA 7 NHibernate: .NET framework 8 JOOQ ORM: JAVA 9 Doctrine: PHP
There are several reasons why JPA-oriented frameworks (Hibernate, for instance) do not fit into idiomatic Scala applications elegantly:
@JoinTable
-> @JoinColumn
);PersistentCollections
, for example);There are more reasons, I'm sure. That's why we have started the Circumflex ORM project. This pure-Scala ORM tries it's best to eliminate the nightmares of classic Java ORMs. Specifically, you define your entities in pretty much way you would do this with classic DDL statements:
class User extends Record[User] { val name = "name".TEXT.NOT_NULL val admin = "admin".BOOLEAN.NOT_NULL.DEFAULT('false') } object User extends Table[User] { def byName(n: String): Seq[User] = criteria.add(this.name LIKE n).list } // example with foreign keys: class Account extends Record[Account] { val accountNumber = "acc_number".BIGINT.NOT_NULL val user = "user_id".REFERENCES(User).ON_DELETE(CASCADE) val amount = "amount".NUMERIC(10,2).NOT_NULL } object Account extends Table[Account]
As you can see, these declarations are a bit more verbose, than classic JPA POJOs. But in fact there are several concepts that are assembled together:
The only things Circumflex ORM lacks are:
P.S. I hope this post will not be considered an advertisement. It isn't so, really -- I was trying to be as objective as possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With