简体   繁体   English

休眠将java Long映射到MySQL BIGINT错误

[英]hibernate mapping java Long to MySQL BIGINT error

I have a Mysql table name customer where 我有一个Mysql表名客户

column Acc_no and Cust_ID are of type BigInt(14) and BigInt(10) respectively 列Acc_no和Cust_ID的类型分别为BigInt(14)和BigInt(10)

and I want to check for values in MySQL through Spring MVC Hibernate 我想通过Spring MVC Hibernate检查MySQL中的值

Bean Class customer 豆类客户

@Id
@GeneratedValue(strategy =GenerationType.AUTO)
@Column(name="Cust_ID")
long Cust_ID;

@Id
@GeneratedValue(strategy =GenerationType.AUTO)
@Column(name="Acc_No")
long Acc_No;

@Column(name="C_New_Pwd")
String C_New_Pwd;

While in CustomerDAOImpl I did this 在CustomerDAOImpl期间,我这样做了

    long custid=Long.parseLong(clog);
    long acc_no=Long.parseLong(accno);

    Session session = sessionFactory.openSession();

    String SQL_QUERY =" from com.mla.Customer as o where o.Cust_ID=? and o.Acc_No=? and o.C_New_Pwd=?";
    Query query = session.createQuery(SQL_QUERY);

    query.setParameter(0,(Long)custid);
    query.setParameter(1, (Long)acc_no);
    query.setParameter(2, pwd);
    List list = query.list();

Exception : com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '9.87654321E9' in column '10' is outside valid range for the datatype INTEGER. 异常: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException:列“ 10”中的“ 9.87654321E9”超出了数据类型INTEGER的有效范围。

Long casting in setParameter I did it on purpose but no help same exception. 在setParameter中长时间转换我是故意这样做的,但没有帮助相同的异常。

Here the solution: 这里的解决方案:

// Convert Long to String.
String custID = Cust_ID.toString();

// Then create the BigInteger
BigInteger bigIntegerCustID = new BigInteger( custID );

query.setParameter(0, bigIntegerCustID);

Regards, 问候,

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

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