How hard can it be to check a JDBC connection?

Filed under: tech — Tags: , , , — thomas11 @ 16:57

This is a long, technical and geeky post – skip if you’re not into that!

Today I faced the problem of checking whether a given JDBC Connection is valid. For the sake of simplicity, let’s just say that “valid” means “it works” – you can successfully issue queries with it.



Your Hibernate association is not persisted?

Filed under: tech — Tags: , , — thomas11 @ 19:57

I spent a really frustrating day struggling with a weird bug in my app: some action would associate two entities via a javax.persistence.ManyToMany-mapped collection.  And this association would just be ignored by Hibernate, the link table/join table remained empty.  Finally, I found the solution in a post by Adrian Smith (and an update specifically for JPA in a comment by Sat Freak).  You saved my day!  I’m linking it here so that people may perhaps find it more easily.

The solution: do a flush(), then a merge(), then a commit().  Looks quite strange to me, and I can’t wrap my head around why that works and all my other approaches didn’t.  But work it does.


databinder 1.1.1 is out with DataTree

Filed under: tech — Tags: , , , , — thomas11 @ 15:36

Recently, Nathan released databinder 1.1.1. I contributed the new DataTree component, which is a Wicket (and thus, Swing) tree with nodes backed by Hibernate-managed entities. It comes with a few AJAXified control links, for instance for adding and deleting nodes. Without Nathan’s substantial help and an addition he made to HibernateObjectModel, the tree wouldn’t be in the good shape it’s now, so thanks!

Your objects acting as tree nodes must implement an interface, but it’s really a minimal tree interface, so you should have those methods anyway:

public interface DataTreeObject<T> {
    public Collection<T> getChildren();
    public void addChild(T child);
    public T getParent();

[Added 2008-04-10] A live demo is up on the databinder site.

An additional tiny addition to the 1.1.1 release from me is that the RemoveRepeaterItemButton can now be configured with a minimum of elements which must remain in the collection. For instance, if you want to let users remove addresses in their profile while one must always be present, you instantiate the button with a minimum of one and when only one address remains, the button disables itself.


Useful Maven commands

Filed under: tech — Tags: , , , — thomas11 @ 17:36

On the current project, we use Maven.  It wasn’t really my choice, I just went along with the Wicket and databinder world where it’s commonly used.  I could get into a rant about the annoying experiences we had with it, but that has been done elsewhere more eloquently than I could put it.  And anyway, let’s be fair: it has its great sides, too.  No more (almost) hunting for jars and manually adding them to the Eclipse build path rocks.  So let me instead just share a few often-used commands, because I find the documentation sorely lacking.

  • mvn source:jar – package (only) the source code into a jar file.
  • mvn install – compile, pack into jar, andcopy to the local maven repository.  Ok, that was straightforward.
  • mvn package – only the jar packaging.
  • mvn eclipse:eclipse – create an Eclipse project for the current project.  Very handy, as it sets the build path.
  • -DdownloadSources=true – a parameter you can add to any command, and probably should: download the sources for every downloaded jar.  Makes debugging and looking up sources from Eclipse a snap.


transconnect on Mac OS X

Filed under: tech — Tags: , — thomas11 @ 10:16

transconnect is a nifty utility allowing transparent TCP net access over a proxy, including authentication. In its current version 1.3-Beta on sourceforge, compiling on Mac OS X fails, however. Here’s how to build and use it on OS X 10.4:

  • Edit libcpath.h to define the correct libc:

#define TCONN_LIBC_PATH "/usr/lib/libc.dylib"
  • Introduce a new target “mac” (or whatever) in the Makefile, anywhere among the other targets:

mac: tconn.c
    glibtool gcc -o tconn.o -c tconn.c
    libtool -dynamic tconn.o -o tconn.dylib -ldl -lSystemStubs
  • That sould suffice for building it:

$ make mac
$ make install
  • Now set the environment variable. LD_PRELOAD, as given in the docs, is not correct for Mac OS. Replace it by DYLD_INSERT_LIBRARIES and also set DYLD_FORCE_FLAT_NAMESPACE:

$ export -p DYLD_INSERT_LIBRARIES="$HOME/.tconn/tconn.dylib"
  • Configure tconn.conf as usual.

I got virtually all necessary info from Thomas Strömberg’s Preloading shared libraries in Mac OS X.

Blog at