Replacing ORM

As Java developers, we are used to handling relational database persistence through the use of mature and well-established JPA frameworks such as Hibernate or EclipseLink. Despite the fact that these frameworks are convenient to use and hide a lot of the complexity for retrieving or updating data that is spread over several tables, Object-Relational Mapping suffers from the Object-Relational Impedance Mismatch problem; in an object-oriented model, you traverse objects via their relationships, whereas in a relational database, you join the data rows of tables, resulting sometimes in an inefficient and cumbersome retrieval of data. (This is further explained on the Wikipedia page, http://en.wikipedia.org/wiki/Object-relational_impedance_mismatch.)

In contrast, the Slick framework that is part of the Typesafe stack proposes to solve the persistence of data to relational databases through a Functional Relational Mapping, which strives for a more natural fit. Some of the additional benefits of Slick include the following two aspects:

  • Conciseness and Type Safety: Instead of running SQL queries by expressing them through strings in Java code, Slick uses plain Scala code to express queries. In JPA, the Criteria API or languages such as JPQL (Java Persistence Query Language) or HQL (Hibernate Query Language) have long tried to make string-based queries more type checked, but are still difficult to comprehend and produce verbose code. With Slick, queries are written concisely using the power of Scala for comprehensions. Type safety of SQL queries was introduced a long time ago in the .Net world through the popular LINQ Framework.
  • Composable and reusable queries: The functional approach adopted by Slick makes composition a natural behavior, a feature that lacks when considering plain SQL as an alternative to ORM.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.165.70