jsjgelei
2013-06-21 10:25
浏览 293
已采纳

hibernate问题

问题:我通过hibernate原生sql子查询获取返回的实体list
异常:
Could not find [color=red]setter [/color]for AD_ID on class com.gtd.rocket.entity.AddressEntity
Could not find setter for AD_ID on class com.gtd.rocket.entity.AddressEntity; nested exception is org.hibernate.PropertyNotFoundException: Could not find setter for AD_ID on class com.gtd.rocket.entity.AddressEntity
分析:实体已经有setter方法
@Id
@GeneratedValue
@Column(name = "ad_id", unique = true, nullable = true)
public int getAd_id()
{
return ad_id;
}
public void setAd_id(int ad_id)
{
this.ad_id = ad_id;
}
sql查询:
String sql = "select * from a_address where ad_id in(:ids) order by ad_id";
Map> params = new HashMap>();
params.put("ids", idlist);

public List executeListBySql(final boolean transformer, final String queryString, final Map values)
{
return getHibernateTemplate().executeFind(new HibernateCallback()
{

        public Object doInHibernate(Session session) throws HibernateException, SQLException
        {
            Query query = session.createSQLQuery(queryString);
            if (transformer)
            {
                query.setResultTransformer(Transformers.aliasToBean(entityClass));
            }
            if (values != null && values.size() > 0)
            {
                query.setProperties(values);
            }
            List list = query.list();
            return list;
        }
    });
}

1条回答 默认 最新

相关推荐 更多相似问题