现在我有2个对象,一个是热线单HotLineInfo,另一个是热线类别HotLineType,一对多关系
(1:N-----HotLineInfo:HotLineType),
//这个是HotLineType实体类
private String hotlineTypeGuid;
private HotlineHotlineInfo hotlineHotlineInfo;
private String hotlineTypeId;
//这个是HotLineInfo实体类
private String hotlineInfoGuid;
private String hotlineId; //热线单号
//还有一些其他属性
private Set hotlineMaintenances = new HashSet(0);
private Set hotlineHotlineTypes = new HashSet(0); 页面上是<input type="checkbox" name="type" value="hotlineId">
<input type="checkbox" name="type" value="hotlineId">
<input type="checkbox" name="type" value="hotlineId"> //这里是Service层的DetachedCriteria 条件判断
DetachedCriteria dc = DetachedCriteria.forClass(HotlineHotlineInfo.class);
请问当type被选择后,如何将其添加为dc的条件,或者说如何查询出包涵某类别的
热线单。
(1:N-----HotLineInfo:HotLineType),
//这个是HotLineType实体类
private String hotlineTypeGuid;
private HotlineHotlineInfo hotlineHotlineInfo;
private String hotlineTypeId;
//这个是HotLineInfo实体类
private String hotlineInfoGuid;
private String hotlineId; //热线单号
//还有一些其他属性
private Set hotlineMaintenances = new HashSet(0);
private Set hotlineHotlineTypes = new HashSet(0); 页面上是<input type="checkbox" name="type" value="hotlineId">
<input type="checkbox" name="type" value="hotlineId">
<input type="checkbox" name="type" value="hotlineId"> //这里是Service层的DetachedCriteria 条件判断
DetachedCriteria dc = DetachedCriteria.forClass(HotlineHotlineInfo.class);
请问当type被选择后,如何将其添加为dc的条件,或者说如何查询出包涵某类别的
热线单。
解决方案 »
- Eclipse Debug Jar包里面的内容有问题
- 为什么下面的java代码,b的值会是2?
- s:checkboxlist 换行
- java如何获得当前java程序所产生的进程号
- unix系统中如何解决Java程序的英文乱码问题
- 求远程关闭进程!
- 再问一个Lucene创建IndexWriter的问题
- 请教在Linux下部署Web应用服务的问题
- (求助)用tomcat+Axis构建Web 服务时,客户端没办法执行!!
- 请问大家:JDO和Hibernate有什么区别呀,或者说有什么关系呀?
- 权限里面角色和职位有什么不同
- ssh集成出现异常 大家帮我看看 java.lang.ClassCastException: java.lang.Long
<input type="checkbox" name="type" value="hotlineId">
<input type="checkbox" name="type" value="hotlineId"> 在通过struts 的时候你就应该能得到type的值是一个数组。
楼主这个要求不需要用DetachedCriteria,这样就可以了:
String hotlineTypeId = "xxxx";
Criteria c1 = session.createCriteria(HotlineHotlineInfo.class);
Criteria c2 = c1.createCriteria("hotlineHotlineTypes");
c2.add(Restrictions.eq("hotlineTypeId", hotlineTypeId));
if(hotTypes!=null){
String hotTypeId = hotTypes[0];
if(hotTypes.length >=2){
for(int i=1;i<hotTypes.length;i++){
hotTypeId =hotTypeId+",'"+ hotTypes[i].trim()+"'";
}
}
dc.add(Restrictions.sqlRestriction("exists (select null from dbo.Hotline_HotlineType where HotlineInfoGUID = this_ .HotlineInfoGUID and HotlineTypeID in ("+hotTypeId+"))"));
}
这样就可以了,呵呵