Menu

Julien Wetterwald

Circular dependencies between entities

One question I am often asked is how to handle circular dependencies between Hibernate entities. Interestingly enough, the answer that people are usually looking for ends up being to a slightly different question; namely, how to handle circular dependencies between entities. Let’s have a look at an example. Consider two entities, Customer and Account, with […]

November 29, 2010

David Fortunato

Migrating a Hibernate Bag to a Hibernate List

We ran into an issue recently where we needed to move from a Hibernate bag to an explicitly ordered list. Our root entity is a TaskSchedule, which has many Task(s). We needed to add a list_index column to the Task table, populate the new column and then update our code to use it. Because Hibernate […]

October 27, 2010

Eishay Smith

Testing with Hibernate

Some of the unit tests I wrote lately involved setting up a data setup in the DB and testing the code using and mutating it. To make it clear, the DB is an in memory DB so the setup is super fast without IO slowdowns. Its very easy to do the setup using hibernate but […]

April 08, 2010

Adam Rosien

Easy to get burned by Hibernate

I got burned by Hibernate the other day. This code throws a ClassCastException; can you see what the trouble might be? return (Integer) session.createSQLQuery( “select count(*) ” + “from trades ” + “where date >= :from and date < :to”) .setParameter(“from”, converter.toString(from)) .setParameter(“to”, converter.toString(to)) .uniqueResult(); Under the covers Hibernate infers the result of the query […]

October 22, 2009