Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 实体类中添加数据库没有的字段属性,实体类没有数据库中字段报错

在Spring框架下,为实体类添加一个数据库表中不存在的列作为临时属性时,需使用@Transient注解避免效验错误。本文介绍如何正确添加注解以确保代码正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

正常使用属性时,会使用request、response来完成;
由于代码基本完成,改代码时,需要添加个属性,为了不改太多代码,只能添加到实体类中
数据库表中没有这个列,spring效验导致报错,
会报类似:Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘userrole’ in 'field list’的错误;
解决方法是加上注解标识它是临时属性,不是数据库字段
在这里插入图片描述

@Transient
加到属性上;

org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'tc_oauth2.sa.app_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by ### The error may exist in com/citycloud/ccuap/tc/admin/projectapp/SysAppMapper.java (best guess) ### The error may involve com.citycloud.ccuap.tc.admin.projectapp.SysAppMapper.querySysAppPage-Inline ### The error occurred while setting parameters ### SQL: SELECT sa.app_name AS appName,sa.client_id AS clientId,oc_d.resource_ids AS resource,oc_d.authorized_grant_types AS authorizedGrantTypes,GROUP_CONCAT(sp.project_id) AS projectIds FROM sys_app AS sa LEFT JOIN sys_project AS sp ON sa.client_id = sp.client_id LEFT JOIN oauth_client_details AS oc_d ON oc_d.client_id = sa.client_id WHERE 1 = 1 group by sa.client_id order by sa.app_id desc LIMIT 0,10 ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'tc_oauth2.sa.app_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'tc_oauth2.sa.app_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'tc_oauth2.sa.app_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 这个应该是数据配置的问题,帮我看看怎么修改数据库配置
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值