thomas11

2008-05-14

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.

(more…)

2008-03-13

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.

2008-03-05

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.

Blog at WordPress.com.