在尝试指定要检索的字段时,Hibernate出现了奇怪的错误

时间:2012-12-08 05:51:12

标签: hibernate hql

我试图在HQL(select)中指定我想要的字段。但是当我这样做时,我继续遇到这个奇怪的问题。

错误消息

java.lang.NumberFormatException: For input string: "staffId"
    java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    java.lang.Integer.parseInt(Integer.java:492)
    java.lang.Integer.parseInt(Integer.java:527)
    javax.el.ArrayELResolver.coerce(ArrayELResolver.java:166)
    javax.el.ArrayELResolver.getValue(ArrayELResolver.java:46)
    org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
    org.apache.el.parser.AstValue.getValue(AstValue.java:183)
    org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
    org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
    org.apache.jsp.views.search.SearchResults_jsp._jspx_meth_c_005fforEach_005f0(SearchResults_jsp.java:209)
    org.apache.jsp.views.search.SearchResults_jsp._jspx_meth_c_005fif_005f0(SearchResults_jsp.java:165)
    org.apache.jsp.views.search.SearchResults_jsp._jspService(SearchResults_jsp.java:96)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
    org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:684)
    org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:678)
    org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
    org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
    org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
    org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
    org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer.write(ChainedDelegateAttributeRenderer.java:76)
    org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:336)
    org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:210)
    org.apache.tiles.template.InsertAttributeModel.end(InsertAttributeModel.java:126)
    org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)
    org.apache.jsp.views.templates.Layout_jsp._jspx_meth_tiles_005finsertAttribute_005f2(Layout_jsp.java:344)
    org.apache.jsp.views.templates.Layout_jsp._jspService(Layout_jsp.java:182)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241)
    org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)
    org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
    org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:690)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
    org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

我的HQL (因为你可以看到它当前设置为给我错误的那个。但是注释掉的那个工作正常)

    //SQL = "from Staff where (surnameSearch is not null) and not (nvl(teleDirectory,'xxx') IN ('N','S','D')) and not (telephoneNumber IS NULL AND alias IS NULL) and (aliasList = 'Y' OR (teleDirectory IN ('A','B'))) and ((nvl(systemIdEnd,sysdate+1) > SYSDATE and entityType = 'P') or (entityType = 'N')) and (departmentSearch NOT like 'SPONSOR%')";
    SQL = "select staffId, parentId, entityType, title, firstname, surname, telephoneNumber, department, role from Staff where (surnameSearch is not null) and not (nvl(teleDirectory,'xxx') IN ('N','S','D')) and not (telephoneNumber IS NULL AND alias IS NULL) and (aliasList = 'Y' OR (teleDirectory IN ('A','B'))) and ((nvl(systemIdEnd,sysdate+1) > SYSDATE and entityType = 'P') or (entityType = 'N')) and (departmentSearch NOT like 'SPONSOR%')";

我也没试过就试过这个。

    SQL = "select staff.staffId, staff.parentId, staff.entityType, staff.title, staff.firstname, staff.surname, staff.telephoneNumber, staff.department, staff.role from Staff staff where (surnameSearch is not null) and not (nvl(teleDirectory,'xxx') IN ('N','S','D')) and not (telephoneNumber IS NULL AND alias IS NULL) and (aliasList = 'Y' OR (teleDirectory IN ('A','B'))) and ((nvl(systemIdEnd,sysdate+1) > SYSDATE and entityType = 'P') or (entityType = 'N')) and (departmentSearch NOT like 'SPONSOR%')";

我的模型类的片段

public class Staff {
    Integer pk;
    String staffId;
    String parentId;
    String entityType;
    String title;
    String firstname;
    String surname;
    String telephoneNumber;
    String department;
    String role;

    String alias;
    String aliasList;
    String departmentSearch;
    String firstnameSearch;
    String roleSearch;
    String surnameSearch;
    String surnameLikeSearch;
    Date systemIdEnd;
    String teleDirectory;

    public Integer getPk() {
        return pk;
    }
    public void setPk(Integer pk) {
        this.pk = pk;
    }

    public String getStaffId() {
        return staffId;
    }
    public void setStaffId(String staffId) {
        this.staffId = staffId;
    }

我的hbm XML片段

<hibernate-mapping>
    <class name="org.flinders.staffdirectory.models.database.Staff" table="teld_summary">
        <id name="pk" column="telsumm_pk" />
        <property name="staffId" column="telsumm_id" />

我查看了我的Oracle数据库并确认“staffId”确实是字符串(或者在我的情况下是varchar2)。

你能帮帮忙吗?感谢

1 个答案:

答案 0 :(得分:0)

您已将staffid映射到列telsumm_id

<property name="staffId" column="telsumm_id" />

telsumm_id可能是一个整数列,因为它的名称以“_id”结尾