开发者

Getting Hibernate Exception : org.hibernate.QueryException: could not resolve property

I have one table with composite key attribute..

For that i have made 2 beans for hibernate annotations mappings..

Now, it works fine for save, update and delete..

But when I am fetching using some criteria, it's giving me "could not resolve property" exception.

My Beans are as follows :

WBList.java

@Entity
public class WBList {

    private WBListPK id;
    private String wb;

    @Id
    public WBListPK getId() {
        return id;
    }
    public void setId(WBListPK id) {
        this.id = id;
    }
    @Column(name = "wb")
    public String getWb() {
        return wb;
    }
    public void setWb(String wb) {
        this.wb = wb;
    }
}

WBListPK.java

@Embeddable
public class WBListPK implements Serializable {

    private int rid;
    private int sid;

    public WBListPK() {
    }
    public WBListPK(Integer rid, Integer sid) {
        this.rid = rid;
        this.sid = sid;
    }
    public int getRid() {
        return rid;
    }
    public void setRid(int rid) {
        this.rid = rid;
    }
    public int getSid() {
        return sid;
    }
    public void setSid(int sid) {
        this.sid = sid;
    }
}

FindByAll Method of My DAO is as follows :

public List<WBList> findByAll(final WBListPK wbListPK, final String wb) {
        List results = null;
        results = this.hibernateTemplate.executeFind(new HibernateCallback() {

            public Object doInHibernate(Session session)
                    throws HibernateException, SQLException {

                Criteria criteria = session.createCriteria(WBList.class);

                if (wb != null) {
                    criteria.add(Expression.like("wb", wb));
                }

                if(wbListPK.getRid()!=0){
                    criteria.add(Expression.eq("rid", wbListPK.getRid()));
                }
                if(wbListPK.getSid()!=0){
                    criteria.add(Expression.eq("sid", wbListPK.getSid()));
                }
                return criteria.list();
            }
        });

        return results;
    }

I am calling this findByAll method from my controller, the code is :

 WBListPK wbListPK = new WBListPK();
 WBList wbList = new WBList();
 wbListPK.setRid(10);
 wbListPK.setSid(20);
 List<WBList> wbListList = this.wbListSecurityProcessor.findByAll(wbListPK, "b");
 System.out.println("wbListList = "+wbListList);

When I am executing above code, it's giving me following exception (with stacktrace):

 org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: rid of: com.sufalam.mailserver.bean.WBList; nested exception is org.hibernate.QueryException: could not resolve property: rid of: com.sufalam.mailserver.bean.WBList
    org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:655)
    org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
    org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
    开发者_运维知识库org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:343)
    com.sufalam.mailserver.dao.WBListDao.findByAll(WBListDao.java:42)
    com.sufalam.mailserver.business.WBListProcessor.findByAll(WBListProcessor.java:33)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
    $Proxy113.findByAll(Unknown Source)
    com.sufalam.mailserver.business.security.WBListSecurityProcessor.findByAll(WBListSecurityProcessor.java:28)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
    $Proxy120.findByAll(Unknown Source)
    com.sufalam.mailserver.presentation.web.WBListManageController.handleRequest(WBListManageController.java:65)
    org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:781)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:726)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:636)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:545)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

root cause

org.hibernate.QueryException: could not resolve property: rid of: com.sufalam.mailserver.bean.WBList
    org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)
    org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)
    org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1379)
    org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
    org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1354)
    org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:434)
    org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:394)
    org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:45)
    org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
    org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:90)
    org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:59)
    org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:69)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1554)
    org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
    com.sufalam.mailserver.dao.WBListDao$1.doInHibernate(WBListDao.java:59)
    org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
    org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:343)
    com.sufalam.mailserver.dao.WBListDao.findByAll(WBListDao.java:42)
    com.sufalam.mailserver.business.WBListProcessor.findByAll(WBListProcessor.java:33)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
    $Proxy113.findByAll(Unknown Source)
    com.sufalam.mailserver.business.security.WBListSecurityProcessor.findByAll(WBListSecurityProcessor.java:28)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
    $Proxy120.findByAll(Unknown Source)
    com.sufalam.mailserver.presentation.web.WBListManageController.handleRequest(WBListManageController.java:65)
    org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:781)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:726)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:636)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:545)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

Please help me if anybody have any solutions..

Thanks in advance..


rid and sid are properties of composite identifier (WbListPK), not the entity itself. You, therefore, need to refer to them accordingly:

if(wbListPK.getRid()!=0){
  criteria.add(Expression.eq("id.rid", wbListPK.getRid()));
}
if(wbListPK.getSid()!=0){
  criteria.add(Expression.eq("id.sid", wbListPK.getSid()));
}

Note the id. prefix. See where clause and referring to id property chapters in Hibernate documentation for more details / examples (they deal with HQL but majority of stuff applies to Criteria API as well)


Well not really a specific answer to this question, but might help other people who get an error like this, for me it was about case sensitivity. In other words, the string property name in the criteria you give has to match the one in your mapper file, for instance:

criteria.add(Restrictions.eq("patient", patient));

I had the error since I had used "Patient" here, while my entity has the property "Patient" and the database table has the field "idPatient", while I had named the relation in mapper file as "patient". Just posting, maybe this will help some people in the future, because I got into this thread by inputting the error in google.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜