Wednesday, October 19, 2011
No JPQL order by query parameters?
Tuesday, September 13, 2011
Groovy and Grails = A refreshing change for Java developers!
I was really going to try and only post things that I come across in everyday Java development on this blog and not promote any one framework, but I can't hold back my excitement about Groovy and Grails.
I have used most of the major Java web frameworks throughout the years in an enterprise setting including: Struts, WebWork, Struts2, JSF and Spring MVC, GWT, Flex. Never has it been easier, quicker and more fun to build a web application using Java technologies.
Its amazing how far things have come since the Struts/JDBC days and its equally amazing that its taken this long for Grails to come about. The JVM has come through in a big way allowing other languages.
Some of my favorite parts about Grails:
- It's built on standard Java technologies that we all use today, Spring, Hibernate, Sitemesh, Maven
- Convention over Configuration
- No more DAOs! With dymanic finder methods you can kiss DAOs goodbye.
- Easy relationship mapping between Entities
- No more complex configuration of Spring and Hibernate! Its all done behind the scenes.
- Plugins! Adding things like full text searching with a few lines of code is awesome.
- FUN, PRODUCTIVE and actually INSPIRING to use!
Many big companies are catching on too, including Netflix!
Check out the podcast here for more information about Netflix and Grails:
here
Also check out these Grails books:
Grails in Action
The Definitive Guide to Grails
Wednesday, August 31, 2011
Spring OpenEntityManagerInViewFilter persistence issues.
When you have the concept of "draftable" entities, that is entities that need to be in a draft state before going live, the OpenEntityManagerInViewFilter causes some strange behavior.
If you have a controller that queries an entity and then you change that entity it will automatically flush at the end of the transaction. Your changes are then persisted even though you may not want them to be. Detaching the object doesn't seem to help in some cases.
Could this be a bad design and a misuse of JPA persistence or is it just something that has to be dealt with while using OpenEntityManagerInViewFilter?
Draftable draftableObject = draftService.loadPossiblyFromDraft(id);
draftableObject.setName("Test");
//Only trying to save the changes as a draft object and not affect the original
draftService.saveAsDraft(draftableObject);
//After the request ends with OpenEntityManagerInViewFilter enabled
//The draftableObject changes are persisted to the entity as well as the draft.