1

I'm not sure where I'm using a String?

public void getRevisionTypeData() {

    List<String> duaRevType = new ArrayList<String>();  


    duaRevType = getRevisionTypes();
    System.out.println("SIZE :" + duaRevType.size());

    for (String revtypes : duaRevType) {

        System.out.println("Revision Types: " + revtypes);

    }

}

When I run the method, I get this castexception

public List<String> getRevisionTypes() {

List<String> revTypes= null;
int num = 833;

try {
    Session session = factory.openSession();
    AuditReader auditReader = AuditReaderFactory.get(session);

    List<String> resultList = auditReader.createQuery()
            .forRevisionsOfEntity(DuaVO.class, DuaVO.class.getName(), false, true)
            .addProjection(AuditEntity.revisionType()).add(AuditEntity.id().eq(num)).getResultList();

     revTypes = resultList;

} catch (HibernateException e) {
    e.printStackTrace();
}

return revTypes;

Console Output

      log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
Hibernate: 
    select
        duavo_aud0_.REVTYPE as col_0_0_ 
    from
        DUA_AUD duavo_aud0_,
        REVINFO defaultrev1_ 
    where
        duavo_aud0_.DUA_NUM=? 
        and duavo_aud0_.REV=defaultrev1_.REV
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    at org.hibernate.type.descriptor.java.StringTypeDescriptor.unwrap(StringTypeDescriptor.java:39)
    at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$1.doBind(VarcharTypeDescriptor.java:64)
    at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:90)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:286)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:281)
    at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:67)
    at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:613)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1900)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1861)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
    at org.hibernate.loader.Loader.doQuery(Loader.java:909)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
    at org.hibernate.loader.Loader.doList(Loader.java:2553)
    at org.hibernate.loader.Loader.doList(Loader.java:2539)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2369)
    at org.hibernate.loader.Loader.list(Loader.java:2364)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:496)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:231)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1264)
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
    at org.hibernate.envers.query.internal.impl.AbstractAuditQuery.buildAndExecuteQuery(AbstractAuditQuery.java:103)
    at org.hibernate.envers.query.internal.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:122)
    at org.hibernate.envers.query.internal.impl.AbstractAuditQuery.getResultList(AbstractAuditQuery.java:109)
    at com.envers.EnversTest.getRevisionTypes(EnversTest.java:104)
    at com.envers.EnversTest.getRevisionTypeData(EnversTest.java:71)
    at com.envers.EnversTest.main(EnversTest.java:50)
4
  • What is the type of REVTYPE in the database? Commented Mar 25, 2015 at 14:19
  • @Zeus Its a Number(3,0) Commented Mar 25, 2015 at 14:20
  • Could you provide the full stack trace ? Commented Mar 25, 2015 at 14:25
  • Please show AuditEntity class Commented Mar 25, 2015 at 14:41

1 Answer 1

2

The problem is in this part of your code

List<Integer> resultList = (List<Integer>) auditReader.createQuery()
                .forRevisionsOfEntity(DuaVO.class, DuaVO.class.getName(), false, true)
                .addProjection(AuditEntity.revisionType()).add(AuditEntity.id().eq(num)).getResultList();

getResultList obviously returns a List which type can't be cast to Integer directly (String).

I believe

duavo_aud0_.REVTYPE

are of VARCHAR type. You will have to convert them when manipulating using Integer.parseInt or change the datatype in the database.


Answer Update (According to discussion in comments)

change

AuditEntity.id().eq(num) 

to

AuditEntity.id().eq(String.valueOf(num))
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.