2 qq 34131878 qq_34131878 于 2017.09.01 12:10 提问

mysql报错Unknown column

本人小白(c币有限,求帮忙!!),在搭建ssh框架时遇到如题的问题,在网上也没有找到解决方案,求大神帮帮忙,在线等:
建表语句:

CREATE TABLE `user` (
  `userId` varchar(100) NOT NULL,
  `userName` varchar(255) DEFAULT NULL,
  `userPassword` varchar(255) DEFAULT NULL,
  `userCreateTime` varchar(255) DEFAULT NULL,
  `userUpdateTime` varchar(255) DEFAULT NULL,
  `userStatus` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('001', 'admin', '123456', null, null, null);

实体类:

 @Entity
@Table(name="USER")
public class User {

    private String userid;//
    private String user_name;//
    private String user_password;//
    private String user_status;//
    private String user_create_time;//
    private String user_update_time;//
    @Id
    @Column(name="userId")
    public String getUserid() {
        return userid;
    }
    public void setUserid(String userid) {
        this.userid = userid;
    }
    @Column(name="userName")
    public String getUser_name() {
        return user_name;
    }
    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }
    @Column(name="userPassword")
    public String getUser_password() {
        return user_password;
    }
    public void setUser_password(String user_password) {
        this.user_password = user_password;
    }
    @Column(name="userStatus")
    public String getUser_status() {
        return user_status;
    }
    public void setUser_status(String user_status) {
        this.user_status = user_status;
    }
    @Column(name="userCreateTime")
    public String getUser_create_time() {
        return user_create_time;
    }
    public void setUser_create_time(String user_create_time) {
        this.user_create_time = user_create_time;
    }
    @Column(name="userUpdateTime")
    public String getUser_update_time() {
        return user_update_time;
    }
    public void setUser_update_time(String user_update_time) {
        this.user_update_time = user_update_time;
    }

用的ssh框架,查询时打印的sql语句正常,但报错,
错误代码如下:

 Hibernate: select user0_.userId as userId1_7_, user0_.userCreateTime as userCrea2_7_, user0_.userName as userName3_7_, user0_.userPassword as userPass4_7_, user0_.userStatus as userStat5_7_, user0_.userUpdateTime as userUpda6_7_ from user user0_ where user0_.userName='admin'
2017-09-01 12:03:34,397 [http-nio-8080-exec-28] WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - SQL Error: 1054, SQLState: 42S22
2017-09-01 12:03:34,397 [http-nio-8080-exec-28] ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - Unknown column 'user0_.userId' in 'field list'
2017-09-01 12:03:34,578 [http-nio-8080-exec-28] WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - SQL Warning Code: 1054, SQLState: 42S22
2017-09-01 12:03:34,578 [http-nio-8080-exec-28] WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - Unknown column 'user0_.userId' in 'field list'

4个回答

Mr_cuiwei
Mr_cuiwei   2017.09.01 13:08
已采纳

“Unknown column 'user0_.userId' in 'field list'”数据库字段可能sql字段可能不一致,查看创建表sql语句是 否有空格,或特殊字符引起错误
分享个链接给你。http://blog.csdn.net/gnail_oug/article/details/53606608

GMingZhou
GMingZhou   2017.09.01 12:47

在属性的方法get上加入@Transient

qq_34131878
qq_34131878 @Transient是非持久化属性啊,这会影响保存数据库吗?而且这些属性本身是与表的字段一一对应的,不加@Transient也应该可以吧?
3 个月之前 回复
GMingZhou
GMingZhou   2017.09.01 12:56

或者你把id换为不要用数字型的字符串,直接用 'abc'试试

qq_34131878
qq_34131878   2017.09.01 13:22

找到问题了。。。。有点想摔头!!!!数据库连错了!!!唉,对自己无语了

qq_34131878
qq_34131878 还是要谢谢各位帮忙,辛苦
3 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片