Thread: Hibernate + setObject() + boolean problem with a patch
We are using Hibernate on top of PostgreSQL and with a recent switch to PostgreSQL 8.0 we ran into a problem that trying to insert rows with null boolean fields to the DB failed miserably. I traced the problem to the fact that Hibernate wants to do this throuhg setObject() and this does not handle null booleans. The attached patch handles the booleans the same way as bits are handled which I think is the correct way (at least it solved our problem). -- * Sufficiently advanced magic is indistinguishable from technology (T.P) * * PGP public key available @ http://www.iki.fi/killer * Index: org/postgresql/jdbc2/AbstractJdbc2Statement.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v retrieving revision 1.72 diff -u -r1.72 AbstractJdbc2Statement.java --- org/postgresql/jdbc2/AbstractJdbc2Statement.java 16 Feb 2005 18:28:45 -0000 1.72 +++ org/postgresql/jdbc2/AbstractJdbc2Statement.java 18 Feb 2005 10:38:44 -0000 @@ -982,6 +982,7 @@ oid = Oid.TIMESTAMPTZ; break; case Types.BIT: + case Types.BOOLEAN: oid = Oid.BOOL; break; case Types.BINARY:
On Fri, 18 Feb 2005, Kalle Kivimaa wrote: > We are using Hibernate on top of PostgreSQL and with a recent switch > to PostgreSQL 8.0 we ran into a problem that trying to insert rows > with null boolean fields to the DB failed miserably. I traced the > problem to the fact that Hibernate wants to do this throuhg > setObject() and this does not handle null booleans. The attached patch > handles the booleans the same way as bits are handled which I think is > the correct way (at least it solved our problem). > This fix is not correct because the Jdbc2 classes must be compilable by a 1.2 and 1.3 JDKs which do not have Types.BOOLEAN available. A fix of this kind would need to go into one of the Jdbc3 classes which are only compiled by >= 1.4 JDKs. I also don't believe your fix is necessary. org.postgresql.test.jdbc3.TypesTest has the following test in it pstmt.setObject(2, null, Types.BOOLEAN) and it works fine. Could you be more clear on what your problem was (with a stacktrace)? If you are using a jdbc2 version driver then it won't work and you need to use a jdbc3 driver. Kris Jurka