Skip to content

首次使用查询date类型的时候报错了 #32

@hanyahui88

Description

@hanyahui88
2016-06-30 10:36:09.807 DEBUG org.apache.ibatis.logging.jdbc.BaseJdbcLogger 145 debug - ==>  Preparing: SELECT ID,CREATE_DATE,UPDATE_DATE,NAME,AGE FROM TEST WHERE ID = ? AND CREATE_DATE = ? AND UPDATE_DATE = ? AND NAME = ? AND AGE = ? 
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='createDate', mode=IN, javaType=class java.util.Date, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.Date

    protected Long id;
    @Column(name = "CREATE_DATE")
    protected Date createDate;    // 创建日期
    @Column(name = "UPDATE_DATE")
    protected Date updateDate;    // 更新日期
    @Transient
    protected Boolean newRecord;
    private String name;
    private int age;

CREATE TABLE `TEST` (
`id`  int(15) NOT NULL ,
`name`  varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`age`  tinyint(4) NOT NULL ,
`create_date`  datetime NOT NULL ,
`update_date`  datetime NOT NULL ,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
ROW_FORMAT=DYNAMIC
;

如果我把date类型的删掉了 报不一样的错
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='name', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
麻烦帮忙看下这个问题,还有我想问下,自动生成的参数类型是不是能匹配上 比如我int类型不加引号,字符串加引号 谢谢

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions