Broken abstractions => broken code

I’ve just received another powerful lesson in this simple concept. When you break your abstractions, it invariably leads to broken code.

Continue reading “Broken abstractions => broken code”

FasterFox – time your pages

I noticed today a little timer at the bottom of a co-worker’s browser, showing him how long the web page he was browsing took to load. This tool just became a part of my standard toolkit – the “Fasterfox extension to Firefox”:http://fasterfox.mozdev.org

I noticed today a little timer at the bottom of a co-worker’s browser, showing him how long the web page he was browsing took to load. This tool just became a part of my standard toolkit – the “Fasterfox extension to Firefox”:http://fasterfox.mozdev.org

Continue reading “FasterFox – time your pages”

Implicit interfaces

Martin Fowler just wrote an entry on implicit interfaces. This actually would be very useful, but I think I can see why language designers wouldn’t adopt it (at least, not outright).

Continue reading “Implicit interfaces”

Equality for Hibernate

There’s a common idiom in Java for writing the equals() method. Straight from the classic book, “Effective Java”, it looks like this:

public boolean equals(Object obj) {
  if (this ==== obj) { return true; }
  if (obj instanceof ThisClass ==== false) { return false; }
  ThisClass other = (ThisClass) obj;
  return this.importantField1.equals(other.importantField1) && this.importantField2.equals(other.importantField2);
}

When using Hibernate, particularly with lazy proxy classes, it’s important that you stick to this idiom!

Continue reading “Equality for Hibernate”

Generics and code clutter

One issue with generics is how much the generic declaration repeats, particularly with collections. Consider this: bc[java]. Map<Date, List> eventBook = new HashMap<Date, List> How ugly… that repeatition gets very wearying over time. Here’s a few tips to deal with it.

One issue with generics is how much the generic declaration repeats, particularly with collections. Consider this:

bc[java]. Map<Date, List> eventBook = new HashMap<Date, List>

How ugly… that repeatition gets very wearying over time. Here’s a few tips to deal with it.

Continue reading “Generics and code clutter”

Hibernate, proxies, and programming to interfaces

When working simply with Hibernate, you end up coding to concrete classes. This violates the idea that you should program to a type, not an implementation. It also means that various things you tend to do with Hibernate (like writing getters and setters) end up “polluting” your domain classes.

When working simply with Hibernate, you end up coding to concrete classes. This violates the idea that you should program to a type, not an implementation. It also means that various things you tend to do with Hibernate (like writing getters and setters) end up “polluting” your domain classes.

Continue reading “Hibernate, proxies, and programming to interfaces”

Hibernate Queries, caching, and mutable criteria

Hibernate has extensive support for caching built in (well, provided by various plugins, actually). This caching means that potentially expensive database operations can be avoided, especially in smaller apps (ie, non-clustered, which actually can go to quite a large size). Most people who use Hibernate caching are used to having object instances cached. Hibernate can … Continue reading “Hibernate Queries, caching, and mutable criteria”

Hibernate has extensive support for caching built in (well, provided by various plugins, actually). This caching means that potentially expensive database operations can be avoided, especially in smaller apps (ie, non-clustered, which actually can go to quite a large size).

Most people who use Hibernate caching are used to having object instances cached. Hibernate can also cache query results. However, there are some things you need to be aware of when you do this.

Continue reading “Hibernate Queries, caching, and mutable criteria”

New article category – Hibernate

I was checking over my web stats recently, and I noticed a trend has emerged solidly over the last few months: most of the search terms that lead to my blog are about Hibernate. Of my top 20 search terms, 11 were about Hibernate, and I’m in the Google top-10 for most of those terms … Continue reading “New article category – Hibernate”

I was checking over my web stats recently, and I noticed a trend has emerged solidly over the last few months: most of the search terms that lead to my blog are about Hibernate. Of my top 20 search terms, 11 were about Hibernate, and I’m in the Google top-10 for most of those terms (somewhat surprisingly…). Now, I’m not talking hundreds of search hits, but I am talking more than dozens.

All up, and at this time, I’ve written ten articles on this site about Hibernate, in various depth. To make life easier for people who are looking here for Hibernate-related material, I’ve added a Hibernate sub-category (underneath the Java category), and put those articles in it.

Caveat: I am not a Hibernate guru. I don’t even play one on TV. I’m merely a Hibernate user who has taken the time to write up things he has found out or thought about. No accuracy is assured, though I will happily accept corrections.

ehcache dissected

At work, we are a heavy user of ehcache. Well, we would be… it was initially written at Wotif, to overcome problems with the Jakarta JCS project. I recently had to sit down and figure out exactly how it works, and thought I’d take a moment to write it up.

*Update*: I tested the Hibernate serialization behaviour. See below for more.

Continue reading “ehcache dissected”

Who needs a structured message format?

Grr… Somewhere in the universe there is a special place put aside for people who think it’s sensible to pass XML data around in a Web Service as an unstructured string.