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.

4 comments:

schrepfler said...

So what is the solution to this problem?

Andre van der Schyff said...

The parameter to your query must be a persisted object

Joel said...

FYI, I just saw this issue when I passed an array instead of a collection ( like List ) as a parameter.

Anonymous said...

Thanks, you saved my day :)