What’s new in simple-jpa 0.5?
06 November 2013 4 Komentar
simple-jpa 0.5 has been released. This release includes new features and important refactoring, which some are not compatible with previous releases. It is not recommended to upgrade your existing project with previous releases to 0.5.
What is simple-jpa? It is a plugin for Griffon. Why do I need simple-jpa? Here is the history…
When I was working in a Spring web based application, I learned about Spring Data Repositories. The documentation says “the goal of Spring Data repository abstraction is to significantly reduce the amount of boilerplate code required to implement data access layers for various persistence stores.” I was so excited at that time. JPA entities instantly have their own CRUD functionality. It feels so right: I should focus on writing business logic (the problem domain) rather than tackling with database access or writing AJAX code in view. Later I learned that Spring Data Repositories was inspired from Grails dynamic finders. I tried to follow tutorials on Grails. It is cool, but I have to learn a new language called Groovy. There is also Spring Roo, a Grails-like convention-over-configuration tool and it is Java-based. I haven’t decided which one is better for me when some people asked me to develop desktop business application. Writing a simple game or graphical application using Java 2D is easy, but business application is a different animal. I feel that Java is not agile enough. I need MVC, dependency injection, dynamic finders and other features to speed up development and reduce complexity. Then I found Griffon. It uses Groovy’s Swing Builder in its view so designing views is very easy even without visual editor. Griffon also introduces MVCGroup to group model, view, and controller in one place and make them available to each other. I then invested my time in learning Groovy and Griffon.
Although Griffon is advertised as Grails’ cousin, some Grails features such as dynamic finders and scaffolding are not yet implemented in Griffon. I feel that those features will increase agility in building desktop business applications. That is why I started simple-jpa development. Its main purpose is to make Griffon as comfortable as possible for developing desktop business-oriented application. I’ve a limited resource so I started with developing very simple finders and primitive scaffolding to aid me in my own projects. Of course they are not as powerful as Grails’ GORM.
I don’t use dynamic finders everywhere. Dynamic finders are useful for simple query but for more complex query, I prefer to use named query. Because named queries are precompiled, they have better performance. I can call a named query in simple-jpa 0.5 by using executeNamedQuery () method. In some cases, I need to search for entities based on one or more conditions. For example, in a typical search screen, user is usually presented with one or more search criteria. I don’t know what query to execute in advance, so I can’t use dynamic finders. In this case, I can use findDomainClassByDsl() which accept a closure with query-like Dsl support. By using if statements inside this Dsl closure, I can easily build query based on certain conditions.
Despite simple-jpa has JPA as part of its name, it has been depending on Hibernate JPA provider. I changed this in simple-jpa 0.5. Now, it doesn’t include particular JPA provider, Bean Validation implementation and JDBC driver. Plugin user can change default dependencies by editing build configuration file in project. But I don’t believe I could rely on JPA in production. I often find myself using provider specific features that are not found in JPA. For example, in most cases, I use Hibernate @Type for persisting Joda-Time types. JPA doesn’t support custom data types aside from @Embeddable entities.
After several attempts to create Griffon’s view, I found out that table binding is best used with Glazed Lists. Groovy built-in table nodes are not designed with Glazed Lists in mind. That is why simple-jpa includes additional SwingBuilder nodes for working with Glazed Lists. Although Griffon’s view with simple-jpa nodes is simpler than plain Java Swing code, I’ve noticed views in my projects have grown more complicated in production. For that reason, I included new nodes for rendering table (such as glazedTable and glazedColumn) in simple-jpa 0.5.
Don’t forget to visit simple-jpa 0.5 documentation in http://jockihendry.github.io/simple-jpa/v0.5.html for more information. It contains the details of all simple-jpa 0.5 features.