Home > Enterprise >  I am getting java.math.BigInteger cannot be cast to java.lang.Integer at return (ArrayList<String
I am getting java.math.BigInteger cannot be cast to java.lang.Integer at return (ArrayList<String

Time:07-29

1

In hibernate 3 version it was working fine but now I have upgraded it to hibernate version 5 and java.math.BigInteger cannot be cast to java.lang.Integer this error is coming

  @Override
    public ArrayList<String[]> getInvoiceDetails(
            BigInteger premiumFeeRelationshipId) {
        LOGGER.info(METHOD_START);
        sessionFactory = getSessionFactory();
        if(sessionFactory!=null){
        session = sessionFactory.openSession();
        }
        Query query = session.createQuery(BrmsCommonConstants.GETINVOICEDETAILS);
        query.setParameter(0, premiumFeeRelationshipId);
        
        LOGGER.info(METHOD_END);
        return (ArrayList<String[]>) query.list();
    }

Error java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Integer at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:19) ~[hibernate-core-5.5.4.Final.jar:5.5.4.Final] at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:46) ~[hibernate-core-5.5.4.Final.jar:5.5.4.Final]

CodePudding user response:

Instead of setParameter() method use setBigInteger() of Query interface:

 @Override
    public ArrayList<String[]> getInvoiceDetails(
            BigInteger premiumFeeRelationshipId) {
        LOGGER.info(METHOD_START);
        sessionFactory = getSessionFactory();
        if(sessionFactory!=null){
        session = sessionFactory.openSession();
        }
        Query query = session.createQuery(BrmsCommonConstants.GETINVOICEDETAILS);
        query.setBigInteger(0, premiumFeeRelationshipId);// instead of setParameter() method use setBigInteger here 
        
        LOGGER.info(METHOD_END);
        return (ArrayList<String[]>) query.list();
    }

CodePudding user response:

@Override
    public ArrayList<String[]> getInvoiceDetails(
            BigInteger premiumFeeRelationshipId) {
        LOGGER.info(METHOD_START);
        sessionFactory = getSessionFactory();
        if(sessionFactory!=null){
        session = sessionFactory.openSession();
        }
        Query<?> query = session.createQuery(BrmsCommonConstants.GETINVOICEDETAILS);
        query.setParameter(0, premiumFeeRelationshipId.intValue());
        
        LOGGER.info(METHOD_END);
        return (ArrayList<String[]>) query.list();
    }

added .intValue() in query.setParameter(0, premiumFeeRelationshipId.intValue()); solved my problem Thank You

  • Related