日期:2014-05-18  浏览次数:20640 次

DetachedCriteria 的Expression.in
<hibernate-mapping>
<class name="com.quanguowuliu.hibernate.pojo.CompanyUserInfo" table="companyUserInfo" schema="dbo" catalog="logistic" lazy="false">
  <id name="uid" type="java.lang.Integer">
  <column name="Uid" />
  <generator class="identity" />
  </id>
  <many-to-one name="companyTypeInfo" class="com.quanguowuliu.hibernate.pojo.CompanyTypeInfo" fetch="select">
  <column name="companyTypeId" />
  </many-to-one>
  <many-to-one name="areaInfo" class="com.quanguowuliu.hibernate.pojo.AreaInfo" lazy="false" fetch="select">
  <column name="areaBid" />
  </many-to-one>

  </class>
</hibernate-mapping>
我写了一个方法
查询某个省的公司,但是每个公司引用的是市区编号
我是这样写的
int count=0;
int pageindex = 1;// 页码
int pagesize = 1;// 页面大小
String type=request.getParameter("type");
request.setAttribute("type", type);
DetachedCriteria c=DetachedCriteria.forClass(CompanyUserInfo.class);
if (request.getParameter("page") != null) {
pageindex = Integer.parseInt(request.getParameter("page"));

}
if(request.getParameter("shengId")!=null){
int id=Integer.parseInt(request.getParameter("shengId"));
//查询市
List<AreaInfo> areaInfoList=areaInfoService.getAreaInfo(id);
c.add(Expression.in("areaInfo.areaBid", areaInfoList));
request.setAttribute("shengId", id);
}



打印出来的语句是这样的
Hibernate: 
  /* criteria query */ select
  this_.Uid as Uid142_0_,
  this_.companyTypeId as companyT2_142_0_,
  this_.areaBid as areaBid142_0_,
  this_.Uname as Uname142_0_,
  this_.Upwd as Upwd142_0_,
  this_.companyName as companyN6_142_0_,
  this_.companyType as companyT7_142_0_,
  this_.Birthday as Birthday142_0_,
  this_.enrolMoney as enrolMoney142_0_,
  this_.personnelCount as personn10_142_0_,
  this_.corporativePerson as corpora11_142_0_,
  this_.Address as Address142_0_,
  this_.type as type142_0_,
  this_.Phone as Phone142_0_,
  this_.Summary as Summary142_0_,
  this_.Mobile as Mobile142_0_,
  this_.Image as Image142_0_,
  this_.Email as Email142_0_,
  this_.InternetSite as Interne19_142_0_,
  this_.Fax as Fax142_0_,
  this_.premeditation1 as premedi21_142_0_,
  this_.premeditation2 as premedi22_142_0_ 
  from
  logistic.dbo.companyUserInfo this_ 
  where
  this_.type=? 
  and this_.areaBid in (
  ?, ?
  )


但是出现了异常
 could not bind value '[Ljava.lang.Object;@2c5f8a' to parameter: 2; [Ljava.lang.Object;
- Unhandled Exception thrown: class java.lang.ClassCastException
2008-10-23 9:46:25 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.C