openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schmidt <>
Subject Scala and JPA
Date Mon, 21 Jun 2010 13:55:43 GMT
You asked me to post further outcome of JPAExtension.

There is nothing really new, but I was able to get some space on one of
the well known Scala Maven repositories. So it should be easier to play
around with JPAExtension. It is located at
(The term extension is currently related to the filter concept, which
allows the usage of type safe holder objects for binding parameter.)

*Advantages of JPAExtension (and Scala) are e.g. :*

* Get rid of the .class parameter (eg. EntitiyManager.find)

val item: ObjectItem = find(id).get

Where the Class of the entity is inferred from the type of item. get is
part of class Option, the Scala "replacement" for none-existent/existent
values (where null is different from non-existent).

* More visual transaction scope wrapper (with stackable traits, which
allow the execution of some pre or post transaction code)

withTrxAndCommit {
  val item = new ObjectItem()
  . . .

* Mixins for e.g. ThreadLocal EntityManager or JNDI
EntityManagerFactory implementations

class MyClass extends Something
    with JndiEntityManagerFactory("jndiName")
    with ThreadLocalEntityManager {
 def getPersistenceUnitName = "mip"
 . . .

* Type safe queries(QueryWrapper)

val resultList = createQuery[ObjectItem]("Select oi from ObjectItem

* functional capabilities like findAndApply or forQueryResults

forQueryResults {
 oi: ObjectItem =>
 . . .
} withQuery (filter)

JPAExtension is my version of a Scala wrapper for JPA (or persistence
layer in general) and is far away from being complete.
What I would like to hear is: what do you think about it?

Or even more general:
Do you think you have to care about Scala?
How does a functional programming language influence the design of already
existing Java frameworks like JPA?
Or is it better to design completely new API (if we want to use
ORM-functionality with a new language. This is kind of reinvent the wheel)?
Or is it better to write some rather "simple" and pragmatic wrapping like
I did?


Some additional resources:
Examples for EM, EMF, Queries:
Some entity examples:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message