Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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)
share|improve this question
    
What is the type of REVTYPE in the database? – Zeus Mar 25 '15 at 14:19
    
@Zeus Its a Number(3,0) – AppSensei Mar 25 '15 at 14:20
    
Could you provide the full stack trace ? – Vyncent Mar 25 '15 at 14:25
    
Please show AuditEntity class – Ishwar Lal Mar 25 '15 at 14:41
up vote 2 down vote accepted

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))
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.