-2

application is not using user_id column and table also doesn't have user_id in users table, but getting error as o.h.engine.jdbc.spi.SqlExceptionHelper : The column name user_id is not valid.

 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.orm.jpa.JpaSystemException: Unable to find column position by name: user_id] with root cause

Dao interface

 @Query(value="Select * from Users u WHERE u.UserName=:username", nativeQuery = true)
User findByUsername(@Param("username") String username) throws SQLException;

Table data

enter image description here

User Model class

enter image description here

Please help on this

developer
  • 9,116
  • 29
  • 91
  • 150
  • As per the question guide, please do not post images of code, data, error messages, etc. - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. – Dale K Jan 17 '23 at 21:12
  • 2
    https://stackoverflow.com/questions/25283198/spring-boot-jpa-column-name-annotation-ignored may this be the issue? – uylmz Jan 17 '23 at 21:14
  • 1
    @uylmz i tried same as above post given @Column(name="UserId") and added properties in application.properties file but now getting error as "h.engine.jdbc.spi.SqlExceptionHelper : The column name UsreId is not valid." – developer Jan 17 '23 at 21:23
  • 1
    @uylmz thanks for providing the link, that post provide partials fix and in the same post there is one more link which is second part of fix. – developer Jan 17 '23 at 22:01

1 Answers1

1

there are multiple fixes for this

we have to annotate @column for each column

and have to use below properties on application.properties

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

and also we have to use mixedcase columne names in hyphens

@Column(name="\"UserId\"")

Provide links to posts that helped me @column and properties

Mixed case cloumn name

developer
  • 9,116
  • 29
  • 91
  • 150