0

I have a problem executing a statement with JPA/Hibernate.

I'm trying to insert a record. The statement will be printed to the console:

Hibernate: insert into loan (amount, auto_renew, billed, billing_date, close_date, comment, currency_id, date_offer_added, duration, earned, interest_abs, loan_ext_id, open_date, operator_fee_abs, operator_fees, platform_fee_abs, platform_fees, range, rate, source_systems_id, user_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
09:32:56.396 [default] [XNIO-2 task-6] WARN  o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 1064, SQLState: 42000 
09:32:56.398 [default] [XNIO-2 task-6] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'range, rate, source_systems_id, user_id) values (0.43967500, 0, 0, null, '2017-0' at line 1 

My DB configuration looks like this:

    datasource:    
     # Local MYSQL DB
     type: com.zaxxer.hikari.HikariDataSource 
     url: jdbc:mysql://localhost:3306/coinlender?useUnicode=true&characterEncoding=utf8&useSSL=false
     username: root
     password: 
jpa:
    database-platform: org.hibernate.dialect.MariaDBDialect
    database: MYSQL
    show-sql: true

How can I get closer to the issue? I can't find the cause of the error.

Can anyone please help me?

Kind regards, David

2
  • Sadly, for you, you have chosen to use a JPA provider that does not auto-quote identifiers that are SQL keywords. Other JPA providers may do this for you, but yours does not, so you have to either change your identifiers to not be SQL keywords!!!, or you have to quote them using @Column etc!!! Commented Aug 11, 2017 at 7:46
  • @NeilStockton Hibernate do so, if you use HQL. But this Looks like plain SQL query and there no JPA Provider escape anything Commented Aug 11, 2017 at 8:16

1 Answer 1

4

range is a keyword in mysql. Do not use it as column name.

BTW if you are using Hibernate/JPA you should use HQL/JPQL not plain sql

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, I renamed the column and it works like a charm!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.