简体   繁体   中英

Hibernate throws exception although the query is working from db console

I'm executing rather complex like this :

session.createSQLQuery("query").setResultTransformer(Transformers.aliasToBean(CheckIn.class));

I'm using couple of AS (ex: select column as columnName from my Table) in my query and hibernate always throws this exception :

Exception in thread "main" org.hibernate.PropertyNotFoundException: Could not find setter for inputrecords on class com.letmedical.store.CheckIn
    at org.hibernate.property.ChainedPropertyAccessor.getSetter(ChainedPropertyAccessor.java:44)
    at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer.java:57)
    at org.hibernate.hql.HolderInstantiator.instantiate(HolderInstantiator.java:69)
    at org.hibernate.loader.custom.CustomLoader.getResultList(CustomLoader.java:330)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    at org.hibernate.loader.Loader.list(Loader.java:2099)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
    at com.letmedical.store.Test.main(Test.java:37)

But there are setters for each class field. What do I do? google doesn't help much since this is not strictly hibernate error.

Update :

I tried to iterate trough result list :

List<CheckIn> list = query.list();  


for (CheckIn object : list) {
                System.out.println(object.getAppTime());
            }

I get this error :

Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.letmedical.store.CheckIn
    at com.letmedical.store.Test.main(Test.java:41)

But all attributes of my object are inside this object but I can't cast it to my object CheckIn. Anyone had this issue?

Update II :

Here is getter/setter :

private Integer inputRecords;

public Integer getInputRecords() {
    return inputRecords;
}
public void setInputRecords(Integer inputRecords) {
    this.inputRecords= inputRecords;
}

My Hibernate mapping :

  <property name="inputRecords" type="java.lang.Integer">
            <column name="inputRecords" not-null="false" />
        </property>

table column is named inputrecords

is there a way arround?

from your stacktrace, you have a field 'inputrecords'. This should be

inputRecords

and the setter should be

public void setInputRecords(...){
...
}

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