combobox值作为作为查询条件查询时Hibernate报错
hibernate配置文件:程序代码:
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate. Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="connection.username"> mvcmaker20160125 </property> <property name="connection.password"> gwideal </property> <property name="connection.url"> jdbc:oracle:thin:@192.0.0.2:1521:jwjf <!-- jdbc:oracle:thin:@localhost:1521:orcl --> <!-- jdbc:oracle:thin:@192.0.0.42:1521:QODB --> </property> <!-- property name="connection.url">jdbc:oracle:thin:@localhost:1521:cndb</property--> <!-- <property name="connection.url">jdbc:oracle:thin:@31.0.128.14:1521:cndb</property> --> <!-- property name="connection.url">jdbc:oracle:thin:@192.0.0.57:1521:orcl</property--> <!--property name="connection.url">jdbc:oracle:thin:@192.0.0.73:1521:mvc1</property--> <property name="dialect"> org.hibernate.dialect.Oracle9Dialect </property> <property name="myeclipse.connection.profile">oracle9</property> <!-- <property name="connection.password">gw</property> --> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </property> <property name="current_session_context_class">thread</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">false</property> <property name="hibernate.hbm2ddl.auto">none</property> <property name="hibernate.cache.provider_configuration_file_resource_path"> /ehcache-hibernate.xml </property> <!-- property name="hibernate.cache.use_query_cache">false</property>--> <property name="hibernate.autoReconnect">true</property> <property name="hibernate.bytecode.use_reflection_optimizer"> true </property> <property name="connection.useUnicode">true</property> <property name="connection.characterEncoding">UTF-8</property> <property name="hibernate.query.substitutions"> true 1, false 0 </property> <property name="hibernate.jdbc.batch_size">20</property> <!-- property name="connection.username">root</property --> <!-- property name="connection.url">jdbc:mysql://localhost:3306/mvcmaker?useUnicode=true&characterEncoding=gbk</property --> <!-- property name="myeclipse.connection.profile">mysql5</property --> <!-- property name="connection.password"></property --> <!-- property name="connection.driver_class">com.mysql.jdbc.Driver</property --> <mapping resource="model/entity/ProjectInfo.hbm.xml" /> <mapping resource="model/entity/ProjectInfoLog.hbm.xml" /> <mapping resource="model/entity/Attachment.hbm.xml" /> <mapping resource="model/entity/NodeDetailInfo.hbm.xml"></mapping> <mapping resource="model/entity/NodeInfo.hbm.xml" /> <mapping resource="model/entity/XmmxNode.hbm.xml" /> <mapping resource="model/entity/HtUser.hbm.xml" /> <mapping resource="model/entity/ExpcetionInfo.hbm.xml" /> <mapping resource="model/entity/HtUserRole.hbm.xml" /> <mapping resource="model/entity/NodeDetailAttment.hbm.xml" /> <mapping resource="model/entity/CzTask.hbm.xml" /> <mapping resource="model/entity/QsTask.hbm.xml" /> <mapping resource="model/entity/PerMonthPlan.hbm.xml" /> <mapping resource="model/entity/XmmxNodeRole.hbm.xml" /> <mapping resource="model/entity/Zjtb.hbm.xml" /> <mapping resource="model/entity/XmmxNodeLog.hbm.xml" /> <mapping resource="model/entity/Dwxx.hbm.xml" /> <mapping resource="model/entity/XmmxAssign.hbm.xml" /> <mapping resource="model/entity/XmmxAttention.hbm.xml" /> <mapping resource="model/entity/NodeLog.hbm.xml" /> <mapping resource="model/entity/Message.hbm.xml" /> <mapping resource="model/entity/ProjectInfoHistory.hbm.xml" /> <mapping resource="model/entity/ProjectInfoNew.hbm.xml" /> <mapping resource="model/entity/ProjectInfoCode.hbm.xml" /> <mapping resource="model/entity/ProjectInfoLink.hbm.xml" /> <mapping resource="model/entity/ProjectClassify.hbm.xml" /> <mapping resource="model/entity/ProjectClassifyTag.hbm.xml" /> <mapping resource="model/entity/ProjectAnnualFund.hbm.xml" /> <mapping resource="model/entity/ProjectExportColumns.hbm.xml" /> <mapping resource="model/entity/SystemConfiguration.hbm.xml" /> <mapping resource="model/entity/ProjectInfoReply.hbm.xml" /> <mapping resource="model/entity/ProjectInfoReplyAnnual.hbm.xml" /> <mapping resource="model/entity/ProjectInfoAssign.hbm.xml" /> <mapping resource="model/entity/ProjectInfoAssignTask.hbm.xml" /> <mapping resource="model/entity/MonthPlanAdjustment.hbm.xml" /> <mapping resource="model/entity/RelateUnit.hbm.xml" /> <mapping resource="model/entity/ProjectInfoXmjsStatus.hbm.xml" /> </session-factory> </hibernate-configuration>
JSP页面代码:
程序代码:
<%@ page language="java" import="java.util.*,model.Entt, model.entts.*" pageEncoding="utf-8"%> <%@ taglib uri="/WEB-INF/tld/page.tld" prefix="p"%> <%@ taglib prefix="c" uri="http://java. taglib prefix="fn" uri="http://java. taglib prefix="fmt" uri="http://java. HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>用户管理 </title> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/easyui/themes/default/easyui.css"/> <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/easyui/themes/icon.css"/> <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/js/easyui/demo.css"/> <script type="text/javascript" src="<%=request.getContextPath() %>/js/easyui/jquery.min.js"></script> <script type="text/javascript" src="<%=request.getContextPath() %>/js/easyui/jquery.easyui.min.js"></script> <script type="text/javascript"> function queryUser(vpageNumber,vpageSize){ $('#form_entt_list').form('submit', { onSubmit: function(param){ param.pageNumber = vpageNumber; param.pageSize = vpageSize; param.jsonOperationType = 'loadJsonList'; return $(this).form('enableValidation').form('validate'); }, success:function(data){ // data = eval('(' + data + ')'); data = $.parseJSON(data); $('#zdglListGrid').treegrid('loadData',{"total" : data.total,"rows" : data.rows}); var pager = $('#zdglListGrid').treegrid('getPager'); $(pager).pagination({ pageNumber:vpageNumber, pageSize:vpageSize, total:data.total, beforePageText: '第',//页数文本框前显示的汉字 afterPageText: '页 共 {pages} 页', displayMsg: '共{total}条数据', onBeforeRefresh: function(){ }, onSelectPage: function (pageNumber, pageSize){//分页触发 queryUser(pageNumber,pageSize); } }); } }); } function onContextMenu(e,row){ e.preventDefault(); $(this).treegrid("select",row.id); $('#mm').menu('show', { left: e.pageX, top: e.pageY }); } function onAdd(){ location.href="<%=request.getContextPath()%>/userEditService?enttname=HtUser"; } <!--页面加载--> $(document).ready(function(){ $('#zdglListGrid').width(document.body.clientWidth); $('#zdglListGrid').height(document.body.clientHeight); <!--加载数据--> $('#zdglListGrid').treegrid({ pagination:true, pageList:[5,20,30], pageSize:5, pageNumber:1, striped:true, rownumbers:false, singleSelect:true, loadMsg:'请稍等,数据加载中...', method:'post', idField: 'id', treeField: 'projectname', toolbar:'#zdglToolbar', onContextMenu:onContextMenu, onLoadSuccess:function(data){ }, onDblClickRow:function(index,row){ } }); queryUser(vpageNumber,vpageSize); }); </script> </head> <body> <c:forEach var="r" items="${context_entt_e_xt_yong_hu.roleIds}"> <c:if test="${r eq '4'}"> <c:set var="statusFlag" value="1"></c:set> </c:if> <c:if test="${r eq '1' or r eq '8'}"> <c:set var="statusFlag" value="2"></c:set> </c:if> <c:if test="${r eq '2' or r eq '3'}"> <c:set var="statusFlag" value="3"></c:set> </c:if> <c:if test="${r eq '6' or r eq '7'}"> <c:set var="statusFlag" value="4"></c:set> </c:if> </c:forEach> <table id="zdglListGrid" title="用户管理" class="easyui-datagrid" toolbar="#toolbar" style="width:800px;height:580px" fitColumns="true",singleSelect="true",fit="true",pagination="true"> <thead> <tr> <th data-options="field:'id',align:'center',resizable:false,hidden:true" width=0px>id</th> <th data-options="field:'username',align:'center',resizable:true" width=100px>用户名称</th> <th data-options="field:'realname',align:'center',resizable:true" width=300px>单位名称</th> <th data-options="field:'roleChinese',align:'center',resizable:true" width=100px>用户角色</th> </tr> </thead> </table> <div id="mm" class="easyui-menu"> <div onclick="append()" data-options="iconCls:'icon-add'">增加</div> <div onclick="remove()" data-options="iconCls:'icon-remove'">删除</div> </div> <div id="toolbar" style="padding: 5px; height: auto"> <form id="form_entt_list" name="form_entt_list" action="showuserListService?enttname=HtUser&oper=query" method="post"> <div> 用户名 <input id="input_query_username" class="easyui-textbox" name="input_query_username" style="width:150px" type="text" id="id_input_query_username" /> 单位名称 <input id="input_query_realname" class="easyui-textbox" name="input_query_realname" style="width:150px" type="text" id="id_input_query_realname" /> 用户角色(可多选) <select id="input_query_roleChinese" class="easyui-combobox" name="input_query_roleChinese" style="width:250px" data-options="multiple:true, panelHeight:'auto'"> <option value="管理员">管理员</option> <option value="区领导">区领导</option> <option value="监管者">监管者</option> <option value="建设者">建设者</option> <option value="代建者">代建者</option> <option value="责任人">责任人</option> </select> <!-- 如果是管理员,则可以看到这个查询条件 --> <c:if test="${statusFlag eq '1'}"> </c:if> </br></br> <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="queryUser(1,5)">查询</a> <a href="#" class="easyui-linkbutton" iconCls="icon-scan" onclick="scan">浏览...</a> <a href="#" class="easyui-linkbutton" onclick="importFile()">导入</a> <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="onAdd()">新增</a> </div> </form> <a href="#" class="easyui-linkbutton" iconCls="icon-tip" plain="true">提示:鼠标左键单击选择列表中项目,右击弹出操作菜单进行操作</a> </div> </body> </html>servlet代码:
程序代码:
package servlet; import import import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.poi.hssf.record.formula.functions.Rows; import servlet.import model.Entt; import model.dao.edao.HtUserDao; import model.dao.edao.HtUserRoleDao; import model.entts.HtUser; import model.entts.HtUserRole; import model.entts.ProjectInfo; import com.fasterxml.jackson.databind.ObjectMapper; /** * �û��б� * @author xie_quqiang * */ public class ShowUserListService extends HttpServlet{ HtUserDao dao=null; HtUserRoleDao urdao=null; public void init() throws ServletException { dao=new HtUserDao(); urdao=new HtUserRoleDao(); super.init(); } public void destroy() { super.destroy(); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{ request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); HttpSession session = request.getSession(); HtUser user=(HtUser)session.getAttribute("context_entt_e_xt_yong_hu"); if(user==null){ request.getRequestDispatcher("/dl").forward(request, response); return; } String jsonCondition = "from HtUser t where t.realname in (select name from Dwxx where type=1) "; /*+ "and (select count(*) from HtUserRole ht where t.id=ht.userId ) >0";*/ String jsonOperationType = request.getParameter("jsonOperationType"); if("loadJsonList".equals(jsonOperationType)){//如果是在加载json数据 Integer pageNumber = Integer.parseInt(request.getParameter("pageNumber")); Integer pageSize = Integer.parseInt(request.getParameter("pageSize")); /*String jsonParaUserName = request.getParameter("jsonParaUserName");//用户名称 String jsonParaRealName = request.getParameter("jsonParaRealName");//单位名称 String jsonParaRoleId = request.getParameter("jsonParaRoleId");//用户角色 if(jsonParaUserName!=null && !jsonParaUserName.trim().equals("")){ jsonCondition = jsonCondition + " and t.username like '%"+jsonParaUserName.trim()+"%'"; } if(jsonParaRealName!=null&&!jsonParaRealName.trim().equals("") && !"请选择".equals(jsonParaRealName)){ jsonCondition+=" and t.realname = '"+jsonParaRealName.trim()+"'"; } if(jsonParaRoleId!=null&&!jsonParaRoleId.trim().equals("") && !"请选择".equals(jsonParaRoleId)){ jsonCondition+=" and t.workoffice = '"+jsonParaRoleId.trim()+"'"; }*/ String yhmc=request.getParameter("input_query_username"); String dwmc=request.getParameter("input_query_realname"); String[] yhjs=request.getParameterValues("input_query_roleChinese"); if(yhmc != null && !yhmc.trim().equals("")){ jsonCondition += " and t.username like '%"+yhmc.trim()+"%'"; } if(dwmc != null && !dwmc.trim().equals("")){ jsonCondition += " and t.realname like '%"+dwmc.trim()+"%'"; } if(yhjs!=null&&yhjs.length>0){ String roleChineseQueryString=CommonUtils.returnKeyFieldsQueryString(yhjs); if(roleChineseQueryString!=null&&roleChineseQueryString.length()>0){ jsonCondition+="and t.rolechinese like '"+roleChineseQueryString+"' "; } } Map<String,Object> result = dao.findUserByConditionAndPagination(jsonCondition, pageNumber, pageSize); List<HtUser> urs = (ArrayList<HtUser>) result.get("rows"); for(HtUser ht:urs){ List<String> roleIds = new ArrayList<String>(); List<HtUserRole> rlist = urdao.findListByUser(ht.getId()); for(HtUserRole ur : rlist){ roleIds.add(ur.getRoleId()); } ht.setRoleIds(roleIds); } ObjectMapper objectMapper = new ObjectMapper(); String resultJson = objectMapper.writeValueAsString(result); System.out.println(resultJson); PrintWriter out = response.getWriter(); out.write(resultJson); out.close(); return; } List<String> roleIds=user.getRoleIds(); String url=""; Entt entt=null; List list_entt; String enttname=""; //ʵ����� if(request.getParameter("enttname")==null){ url="enttname_is_null.jsp"; request.getRequestDispatcher(url).forward(request, response); return; }else{ enttname=request.getParameter("enttname"); } String username=request.getParameter("input_query_username"); String realname=request.getParameter("input_query_realname"); String roleChinese=request.getParameter("input_query_roleChinese"); HtUser htUser=new HtUser(); Object o_entt=(model.EnttFactory.get_a_entt_by_enttname(enttname)); if(o_entt==null){ url="entt_not_exist.jsp?enttname="+enttname; request.getRequestDispatcher(url).forward(request, response); return; }else{ entt=(Entt)o_entt; } String condition=request.getParameter("condition"); // String sqlpart=""; if(username!=null&&!username.trim().equals("")){ sqlpart+=" and username like '%"+username.trim()+"%'"; } if(roleIds.contains("4")){ if(realname!=null&&!realname.trim().equals("")){ sqlpart+=" and realname like '%"+realname.trim()+"%'"; } } if(roleIds.contains("2")||roleIds.contains("3")){ sqlpart+=" and realname like '"+user.getRealname()+"'"; } if(roleChinese!=null&&!roleChinese.trim().equals("")){ sqlpart+=" and id in (select userid from t_yw_userrole where roleid='"+roleChinese+"')"; } if(condition==null||condition.trim().equals("")){ condition=" where isuse= '1' "; } condition=condition+sqlpart; String oper = "query"; String exec = ""; String labType = request.getParameter("labType"); if(labType == null) labType = "xmyap"; int startPage = 1; int records = model.dao.EnttDAO.get_Entt_Count(enttname, condition); int countPage = 10; String page_arg = request.getParameter("startPage"); String countpage_arg = request.getParameter("countPage"); if (page_arg != null) startPage = Integer.parseInt(page_arg); if (countpage_arg != null) countPage = Integer.parseInt(countpage_arg); int pages = records % countPage == 0 ? records / countPage : records / countPage + 1; list_entt = new ArrayList(); list_entt = model.dao.EnttDAO.get_Entt_List(enttname, condition, startPage, countPage); if(list_entt!=null&&list_entt.size()>0){ List<HtUser> users=list_entt; for(HtUser u:users){ List<HtUserRole> urs=urdao.findListByUser(u.getId()); List<String> roleIdsTemp=new ArrayList<String>(); for(HtUserRole ht:urs){ roleIdsTemp.add(ht.getRoleId()); } u.setRoleIds(roleIdsTemp); } } request.setAttribute("startPage",startPage); request.setAttribute("list_"+enttname, list_entt); request.setAttribute("countPage", "" + countPage); request.setAttribute("maxpage", "" + pages); request.setAttribute("records", "" + records); request.setAttribute("username", username); request.setAttribute("realname", realname); request.setAttribute("roleChinese", roleChinese); url="view/user/showuserList.jsp?enttname="+enttname+"&oper="+oper+"&exec="+exec; request.getRequestDispatcher(url).forward(request, response); } }
页面如下图所示:
选中“监管者”点击查询时,hibernate报错如下:
严重: Servlet.service() for servlet showuserListService threw exception
org.hibernate.QueryException: could not resolve property: rolechinese of: model.entts.HtUser [select count(*) from model.entts.HtUser t where t.realname in (select name from model.entts.Dwxx where type=1) and t.rolechinese like '%监管者%' ]
请问各位大神这个问题怎么破???谢谢!!!