• Home
  • RSS Feed
  • Log in

Author Archive


Understanding and writing Hibernate custom user types
Posted by Andrew Phillips mid-morning: November 9th, 2009

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…)

Share

Tags: Hibernate, Hibernate user type, JPA
Filed under Java | 17 Comments »


Testing Annotation Processors
Posted by Andrew Phillips in the early evening: July 21st, 2009

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.

(more…)

Share

Tags: annotation processor, Java, model api, Testing
Filed under Java, Testing | 3 Comments »


@Composite – Macro Annotations for Java
Posted by Andrew Phillips in the early morning: June 23rd, 2009

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…)

Share

Tags: annotation, composite, Java, macro, Spring
Filed under Java | 6 Comments »


Life on Tour: JAX 2009 Conference Review
Posted by Andrew Phillips in the wee hours: April 30th, 2009

jax09_logo
jax09_3_in_1

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…)

Share

Tags: Agile, conference, Eclipse, Eclipse Forum, JAX, OSGi, SOACON
Filed under Agile, General, Java | 4 Comments »


Declarative equality for your business domain objects
Posted by Andrew Phillips mid-afternoon: April 24th, 2009

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…)

Share

Tags: business key, domain object, equals, hashcode, Java
Filed under Java | 4 Comments »


Dynamic enums in Java
Posted by Andrew Phillips in the wee hours: April 2nd, 2009

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…)

Share

Tags: dynamic, enum, Java, pattern
Filed under Java | 6 Comments »


HSQLDB “database already in use by another process” exceptions on UNIX
Posted by Andrew Phillips mid-afternoon: March 20th, 2009

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…)

Share

Tags: Techlist
Filed under Java, Tools | 2 Comments »


A general-purpose utility to retrieve Java generic type values
Posted by Andrew Phillips in the early afternoon: March 12th, 2009

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…)

Share

Tags: generics
Filed under Java | 9 Comments »


Gotcha! Watch out when overriding bean property accessors…
Posted by Andrew Phillips in the early morning: March 6th, 2009

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…)

Share

Tags: beans, beanutils, bug, Java
Filed under Java | No Comments »

Newer posts →

Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India
  • XebiCon 2012

Categories

  • Java (312)
  • Agile (192)
  • General (141)
  • Scrum (70)
  • Testing (65)
  • Architecture (65)
  • Performance (47)
  • Middleware (59)
    • Deployment (40)
  • Xebia Labs (41)
  • SOA (31)
  • Project Management (31)
  • Podcast (31)
  • Tools (28)
  • Uncategorized (24)
  • lean architecture (20)
  • Quality Assurance (19)
  • Articles (15)
  • Requirements Management (14)
  • Virtualization (21)

Tag Cloud

    Groovy Xebia XML Javascript lean architectuur Hibernate Ajax Scrum product owner TDD lean architecture JPA SOA Flex Architecture Spring ACT Lean Concurrency Control Maven Agile Eclipse Scala JPA implementation patterns Frameworks agile architectuur Java Grails Oracle Moving to India

Archives

  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
Avatars by Sterling Adventures