简体   繁体   中英

application is not using user_id and table also doesnt have user_id in users table, but getting error as The column name user_id is not valid

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

在此处输入图像描述

User Model class

在此处输入图像描述

Please help on this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM