In the careers of most Spring/Hibernate developers I know, there sooner or later comes a point of no escape…they have to write a Hibernate user type. The first one is usually of the copy’n'paste variety, and by and large works perfectly well.
But when things are no longer going quite as expected – Hibernate is ignoring changes to items managed by the user type, for instance – it often becomes apparent that one doesn’t sufficiently understand how these user type thingies are supposed to work. At least, that’s what happened to me.
In this post, we’ll be dissecting the Hibernate UserType interface, explaining the relationships between the various methods, and developing a set of base user types that capture common use cases. (more…)
Tags: Hibernate, Hibernate user type, JPA
Filed under Java | 17 Comments »
Recently, I was writing an Annotation Processor for the @Composite project. In good TDD fashion, that first and foremost meant writing some tests.
Although I in the end come across something that was fairly workable, it was trickier than one might have hoped for.
Tags: annotation processor, Java, model api, Testing
Filed under Java, Testing | 3 Comments »
Some months ago I attended a presentation at which Wilfred Springer demonstrated his very cool Preon binary codec library. Defining binary file formats in Preon requires quite a lot of fairly repetitive sets of annotations, and during a chat after the talk Wilfred mentioned (in fact, he blogged about it) how much more convenient it would be if one could just define “shortcuts”:
@RequiredEnumProperty(column = "AGENT")
for
@NotNull
@Column(name = "AGENT")
@Enumerated(EnumType.STRING)
for instance – and use those instead. Sort-of “macro annotatations” for Java, if you like.
A thought that has presumably also occurred to many frequent users of Hibernate, JAXB or other annotation-heavy frameworks.
Well, it took me rather longer than the couple of days it would probably have taken a developer of Wilfred’s skill, but finally @Composite is here! (more…)
Tags: annotation, composite, Java, macro, Spring
Filed under Java | 6 Comments »


Last week I attended JAX ’09, the Java User Conference in Mainz, Germany.
Or rather “conferences”, because once you’re there JAX is indistinguishable from something called SOACON and the Eclipse Forum Europe, which officially take place in parallel. (more…)
Tags: Agile, conference, Eclipse, Eclipse Forum, JAX, OSGi, SOACON
Filed under Agile, General, Java | 4 Comments »
As Josh Bloch writes, for business objects, “overriding the equals method [is] necessary to satisfy programmer expectations.” (Effective Java, item 7). Apart from benefits he mentions – conformance to expectations, correct use in maps and sets etc. – I’ve found that implementing equals (and hashCode) really make you consider what the classes represent. Certainly for business objects, i.e. objects in your domain model, trying to define a business-level identity for your classes is a good way of validating that you’ve correctly captured a business-relevant concept.
An equals definition can also serve as a useful piece of documentation describing your domain. Here, we’ll consider an approach that tries to do this as cleanly and conveniently as possible…declaratively! (more…)
Tags: business key, domain object, equals, hashcode, Java
Filed under Java | 4 Comments »
The introduction of Enums in Java 5 finally provided a powerful (and slightly magical) way of modelling fixed sets. One can have too much of a good thing, however, and in some situations an enum is a little too fixed to be convenient.
Here, I’d like to discuss a pattern I’ll call – for want of a better name – the dynamic enum, that addresses this issue. (more…)
Installing a simple Grails application in Tomcat on Linux should really have been the most straightforward of tasks. Instead, I spent a progressively more frustrating morning chasing down a “helpful” feature of HSQLDB that was causing the startup to fail with
org.hsqldb.HsqlException: The database is already in use by another process: org.hsqldb.persist.NIOLockFile@6b67bdbe[file =/myDb.lck, exists=true, locked=false, valid=false, fl=null]
exceptions. To save others from a similar waste of time, here’s the cause and a workaround: (more…)
Tags: Techlist
Filed under Java, Tools | 2 Comments »
In a recent post, Arjan Blokzijl discussed how Class.getGenericSuperclass can be used to access generic type information.
This can be very useful, but implementing a general-purpose method to do this isn’t as straightforward as it might seem. In this post, we’ll outline some of the issues and hopefully resolve them, creating a utility class in the process. After all, with luck this is the kind of code that only needs to be written once! For the curious or impatient, here it is. (more…)
Tags: generics
Filed under Java | 9 Comments »
Whilst working on a bean deep cloning utility recently (more about that some other time) I got stuck for a while on some unexpected behaviour exhibited by java.beans.Introspector. I don’t know many people who use this class directly, but it’s heavily used by, amongst others, the Apache BeanUtils, so if you’re using those you might still come across this issue.
The problem arises if you happen to have overridden bean property accessors in your classes. (more…)