0

I'm using Postgres 9.4.1209, Spring Boot 1.4.0 and Hibernate 5.0.9 and trying to send a dynamic paginated query to a Spring Data Repository. This results in an error whenever my model class has an attribute named in camelCase.

The generated HQL in Hibernate's QueryTranslatorImpl is correct:

select count(payment) from it.my.company.Payment payment where payment.externalId in (?1)

But the generated SQL comes out with an extra underscore where I have camelCase attribute names, so externalId becomes external_id

select count(payment0_.id) as col_0_0_ from payment payment0_ where payment0_.external_id in (?)

Unsurprisingly, this query fails, because there is no external_id column in my database.

I've used both the Criteria API directly, the Spring Specification API, and QueryDSL Predicates, and have the same error popping out of Hibernate each time.

As a workaround, I've tried renaming all of my model class attributes to be entirely lowercase, which takes care of the error. But I don't want rename all of my attributes to a less readable style because of this bug =/

Has anyone seen anything like this before? I'm currently debugging my way through Hibernate's HqlSqlBaseWalker, but that's not the most readable piece of code.

Alex Pruss
  • 533
  • 5
  • 15

1 Answers1

1

I think the problem is that postgresql has its own naming conventions.

For example name identifier like column names should be in lower_case_with_underscores.

There are much ansers and discussions outside regarding your problem.

Not sure if there is a "real" solution but there a good best practices and how to's.

Here are some:

PostgreSQL naming conventions

Underscores or camelCase in PostgreSQL identifiers, when the programming language uses camelCase?

Are PostgreSQL column names case-sensitive?

Hope some of this answers helps. I will also look further to is issue to find the "real" solution.

Community
  • 1
  • 1
Patrick
  • 12,336
  • 15
  • 73
  • 115
  • Renaming my columns to fit the naming convention is at least a much cleaner fix than renaming the model attributes themselves. – Alex Pruss Sep 07 '16 at 10:39