简体   繁体   English

应用程序未使用 user_id,并且表在用户表中也没有 user_id,但出现错误,因为列名 user_id 无效

[英]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.应用程序未使用 user_id 列且表在用户表中也没有 user_id,但出现错误o.h.engine.jdbc.spi.SqlExceptionHelper:列名 user_id 无效。

 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用户 Model class

在此处输入图像描述

Please help on this请帮忙解决这个问题

there are multiple fixes for this对此有多个修复

we have to annotate @column for each column我们必须为每一列注释@column

and have to use below properties on application.properties并且必须在 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提供对我有帮助的帖子的链接@column 和 properties

Mixed case cloumn name 大小写混合的列名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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