Tagged In hibernate :
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… Read more
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… Read more
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… Read more
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… Read more