我的代码是在UAT DB的表'mast'中使用休眠方式提交一个bean,

session.save(userWalletConfigBean);
transaction.commit()


一切正常
但是,在我的生产环境中,它抛出了一个错误

Hibernate: insert into mast (wId, no, emailid, password,
name, usertype, userstatus, creationDate, aggreatorid, distributerid,
agentid, subagentid, createdby, loginStatus, lastlogintime, address1,
address2, city, state, pin, pan, adhar, kycstatus, approvalrequired,
agent, loginipiemi, loginagent, oldpassword, id)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2017-11-10/23:00:11.340
WARN: util.JDBCExceptionReporter - SQL Error: 1292, SQLState: 22001
2017-11-10/23:00:11.341
ERROR: util.JDBCExceptionReporter - Data truncation: Truncated incorrect DOUBLE value: 'DIST001001'
2017-11-10/23:00:11.342
ERROR: def.AbstractFlushingEventListener - Could not synchronize database state with session


经过进一步检查,我发现这是由于SQL的严格模式

我从UAT表中获取了一个插入查询,并尝试直接在Production数据库上运行它,这使我在生产DB的日志中遇到相同的Truncated incorrect DOUBLE value问题。

之后,我禁用了生产数据库的严格模式,并能够直接成功运行插入查询。

但是,即使在此之后,在生产环境上运行时,我的代码也面临着相同的问题。

我已经仔细检查了UAT和生产的表是否相同,没有任何变化。

我想知道的是如何解决这个问题。

如果需要其他任何条件,请告诉我。

任何帮助表示赞赏。

下面是我的实体映射的bean

    @Entity
    @Table(name="mast")
    public class Mast implements Serializable{

        @Id
        @Column(name="id",length =30)
        private String id;

        @Column(name="wid",length =50,nullable = false,updatable=false)
        private String wId;

        @Column(name = "mobileno", unique = true, nullable = false, length = 12)
        private String mobileno;

        @Column(name = "emailid", unique = true, nullable = false, length = 100)
        private String emailid;

        @Column(name = "password", nullable = false, length = 100)
        private String password;

        @Column(name = "name", nullable = false, length = 100)
        private String name;

        @Column(name = "usertype", nullable = false, length = 2 ,columnDefinition = "int default 0")
        private int usertype;

        @Column(name = "userstatus", nullable = false, length = 2)
        private String userstatus;

        @Column(columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
        private Date creationDate;

        @Column(name = "aggreatorid", nullable = true, length = 100)
        private String aggreatorid;

        @Column(name = "distributerid", nullable = true, length = 100)
        private String distributerid;

        @Column(name = "agentid", nullable = true, length = 100)
        private String agentid;

        @Column(name = "subagentid", nullable = true, length = 100)
        private String subAgentId;

        @Column(name = "createdby", nullable = true, length = 100)
        private String createdby;

        @Column(name = "loginStatus", nullable = false, length = 2 ,columnDefinition = "int default 0")
        private int loginStatus;

        @Column(columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
        private Date lastlogintime;

        @Column(name="address1",length =50,nullable = true)
        private String address1;

        @Column(name="address2",length =50,nullable = true)
        private String address2;

        @Column(name="city",length =50,nullable = true)
        private String city;

        @Column(name="state",length =50,nullable = true)
        private String state;

        @Column(name="pin",length =50,nullable = true)
        private String pin;

        @Column(name="pan",length =20,nullable = true)
        private String pan;

        @Column(name="adhar",length =20,nullable = true)
        private String adhar;

        @Column(name="kycstatus",length =20,nullable = true)
        private String kycstatus;

        @Column(name = "approvalrequired", nullable = true, length = 2)
        private String approvalRequired;

        @Column(name = "agent",  length = 300 )
        private String agent;

        @Column(name = "loginipiemi",  length = 20 )
        private String loginipiemi;

        @Column(name = "loginagent",  length = 300 )
        private String loginagent;

        @Column(name = "oldpassword",  length = 1000 )
        private String oldPassword;


    }


下面是我的数据库架构

    CREATE TABLE mast (
        id VARCHAR(30) NOT NULL,
        wid VARCHAR(50) NOT NULL,
        mobileno VARCHAR(12) NOT NULL,
        emailid VARCHAR(100) NOT NULL,
        password VARCHAR(100) NOT NULL,
        name VARCHAR(100) NOT NULL,
        usertype INT(11) NOT NULL DEFAULT '0',
        userstatus VARCHAR(2) NOT NULL,
        creationDate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
        aggreatorid VARCHAR(100) NULL DEFAULT NULL,
        distributerid VARCHAR(100) NULL DEFAULT NULL,
        agentid VARCHAR(100) NULL DEFAULT NULL,
        subagentid VARCHAR(30) NULL DEFAULT NULL,
        createdby VARCHAR(100) NULL DEFAULT NULL,
        loginStatus INT(11) NOT NULL DEFAULT '0',
        lastlogintime TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
        address1 VARCHAR(50) NULL DEFAULT NULL,
        address2 VARCHAR(50) NULL DEFAULT NULL,
        city VARCHAR(50) NULL DEFAULT NULL,
        state VARCHAR(50) NULL DEFAULT NULL,
        pin VARCHAR(50) NULL DEFAULT NULL,
        pan VARCHAR(20) NULL DEFAULT NULL,
        adhar VARCHAR(20) NULL DEFAULT NULL,
        kycstatus VARCHAR(20) NULL DEFAULT NULL,
        approvalrequired VARCHAR(2) NULL DEFAULT NULL,
        prepaidcardnumber VARCHAR(20) NULL DEFAULT NULL,
        agent TEXT NULL,
        loginipiemi VARCHAR(20) NULL DEFAULT NULL,
        loginagent TEXT NULL,
        oldpassword TEXT NULL,
        PRIMARY KEY (id)
    )COLLATE='utf8_general_ci'
ENGINE=InnoDB;

最佳答案

事实证明,这不是代码问题,而是整个数据库本身。
在数据库中,使用不同的“ COLLATE”和“ ENGINE”创建了许多表。

一位高级开发人员建议使用备份脚本并重新部署整个数据库,但是这次在所有表中都使用相同的“ COLLATE”和“ ENGINE”。显然可以做到这一点。

我不知道这是否是解决此问题的正确方法,但对我有用。

谢谢@tadman @Antoniossss和@JBNizet的支持

10-08 02:49