0

I'm using springboot, spring jpa repository and hibernate.

I'm trying to make a save over an object and I get an error: SQL Error: 8152, SQLState: 22001

In application.properties I have:

spring.jpa.show-sql=true

spring.jpa.properties.hibernate.use_sql_comments=true

spring.jpa.properties.hibernate.format_sql=true

but the info in console is:

insert into Table(field1, field2, field3) 
        values
            (?, ?, ?)

In my case I have about 25 fields and I dont know how to debug this to see which field is causing the problem. For instance the query with the data to test in my sql server.

Is there a way to get more info about it??

Thanks

davisoski
  • 727
  • 2
  • 14
  • 41
  • 2
    Can try to change logging level in `application.properties`. Something like `logging.level.org.hibernate=DEBUG` or `logging.level.org.hibernate.SQL=DEBUG` or in custom `logback.xml` More info: https://stackoverflow.com/q/30118683/1032167 – varren Sep 18 '17 at 23:36
  • Show more info, not exactly the info that I need but it enough. – davisoski Sep 19 '17 at 13:03

1 Answers1

0

All you need is to get the generated sql and the values passed in that query.

  1. Declare a log file name in application.properties

    logging.file=logs/demo.log

  2. Provide appropriate appenders and loggers in logback-spring.xml

To get the SQL

<logger name="org.hibernate.SQL" level="DEBUG" additivity="true">
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="FILE" />
</logger>

To get the sql binded paramters

<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" additivity="true">
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="FILE" />
</logger>
zikzakjack
  • 972
  • 2
  • 9
  • 20