Saturday, August 4, 2007

Hibernate / PostgreSQL issue: operator does not exist: bigint = bytea

This one comes up during HQL and criteria queries seldom enough to confuse the hell out of me every time I see it. However, the problem is always exactly the same thing:

You are generating your schema from your hibernate mappings, and one of your query parameters are either null or transient.

What happens is that the generated schema, with postgresql, uses bytea as the type of the foreign key when mapping collections. Describe the table that the collection gets persisted in and you'll see it. Then, Hibernate does explicit typecasting to change it to an int or bigint when you pass in a value, but when you pass in null it breaks down and you get the above error.