简体   繁体   中英

hibernate mapping java Long to MySQL BIGINT error

I have a Mysql table name customer where

column Acc_no and Cust_ID are of type BigInt(14) and BigInt(10) respectively

and I want to check for values in MySQL through Spring MVC Hibernate

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

    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.

Long casting in setParameter I did it on purpose but no help same exception.

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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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