org.hibernate.exception.DataException:无法执行查询

时间:2013-12-10 13:18:43

标签: hibernate

我正在通过条件执行查询 -

 try {
        hsSession  = HibernateUtil.getSession();
        List<StdOrgUsersV> l = (List<StdOrgUsersV>) hsSession.createCriteria(StdOrgUsersV.class)
                .add(Restrictions.eq("partyType", ptype))
                .add(Restrictions.isNotNull("userId")).list();
        for(StdOrgUsersV souv:l){
            ar.add(souv.getUserId());
            ar.add(souv.getPartyFullName());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

StdOrgUsersV类 -

@Column(name = "ID", nullable = false)
@Id
@GeneratedValue(generator = "generator")
@Basic(optional = false)
@GenericGenerator(name = "generator", strategy = "increment")
private long id;
@Column(name = "USER_ID", nullable = false)
private long userId;
@Column(name = "ORG_UNIT_ID", nullable = false)
private long orgUnitId;
@Column(name = "INTERNAL_FLAG")
private Boolean internalFlag;
@Column(name = "PARENT_USER_ID")
private Long parentUserId;
@Column(name = "ROLE_ID")
private Long roleId;
@Column(name = "DEPARTMENT", length = 20)
private String department;
@Column(name = "USER_LOCATION_ID")
private Long userLocationId;
@Column(name = "SCREEN_WIDTH")
private Integer screenWidth;
@Column(name = "SCREEN_HEIGHT")
private Integer screenHeight;
@Column(name = "COMMENTS", length = 1000)
private String comments;
@Column(name = "REV_REF_ID")
private Long revRefId;
@Column(name = "REVISION_NO", nullable = false)
private int revisionNo;
@Column(name="ACTIVE_FLAG", nullable=false)
private boolean activeFlag;
@Column(name = "START_DATE", nullable = false, length = 23)
@Temporal(javax.persistence.TemporalType.DATE)
private Date startDate;
@Column(name = "END_DATE", length = 23)
@Temporal(javax.persistence.TemporalType.DATE)
private Date endDate;
@Column(name = "CREATED_BY", nullable = false)
private long createdBy;
@Column(name = "CREATION_DATE", nullable = false, length = 23)
@Temporal(javax.persistence.TemporalType.DATE)
private Date creationDate;
@Column(name = "UPDATED_BY")
private Long updatedBy;
@Column(name = "UPDATE_DATE", length = 23)
@Temporal(javax.persistence.TemporalType.DATE)
private Date updateDate;
@Column(name = "APPROVAL_LIMIT", precision = 18)
private BigDecimal approvalLimit;
@Column(name = "user_name", length = 50)
private String userName;
@Column(name = "role_name", length = 50)
private String roleName;
@Column(name = "Org_Type_Name", length = 100)
private String orgTypeName;
@Column(name = "ORG_UNIT_TYPE", length = 10)
private String orgUnitType;
@Column(name = "PARTY_TYPE", length = 20)
private String partyType;
@Column(name = "ORG_UNIT_NAME", length = 50)
private String orgUnitName;
@Column(name = "Dept_Name", length = 100)
private String deptName;
@Column(name = "parent_party_name", length = 100)
private String parentPartyName;
@Column(name = "Party_id")
private Long partyId;
@Column(name = "Party_Full_Name", length = 100)
private String partyFullName;
@Column(name = "LOCATION_NAME", length = 50)
private String locationName;
@Column(name = "Loc_Type_Name", length = 100)
private String locTypeName;
@Column(name = "LOCATION_TYPE", length = 20)
private String locationType;
@Column(name = "parent1_id")
private Long parent1Id;
@Column(name = "parent1_loc_name", length = 50)
private String parent1LocName;
@Column(name = "parent1_loc_type", length = 20)
private String parent1LocType;
@Column(name = "parent2_id")
private Long parent2Id;
@Column(name = "parent2_loc_name", length = 50)
private String parent2LocName;
@Column(name = "parent2_loc_type", length = 20)
private String parent2LocType;
@Column(name = "parent3_id")
private Long parent3Id;
@Column(name = "parent3_loc_name", length = 50)
private String parent3LocName;
@Column(name = "parent3_loc_type", length = 20)
private String parent3LocType;
@Column(name = "parent4_id")
private Long parent4Id;
@Column(name = "parent4_loc_name", length = 50)
private String parent4LocName;
@Column(name = "parent4_loc_type", length = 20)
private String parent4LocType;
@Column(name = "parent5_id")
private Long parent5Id;
@Column(name = "parent5_loc_name", length = 50)
private String parent5LocName;
@Column(name = "parent5_loc_type", length = 20)
private String parent5LocType;
@Column(name = "parent_role_id")
private Long parentRoleId;
@Column(name = "Parent_Role_Name", length = 50)
private String parentRoleName;
@Column(name = "ORG_ADDRESS", length = 200)
private String orgAddress;
@Column(name = "parent1_role_id")
private Long parent1RoleId;
@Column(name = "parent1_role_name", length = 50)
private String parent1RoleName;
@Column(name = "parent2_role_id")
private Long parent2RoleId;
@Column(name = "parent2_role_name", length = 50)
private String parent2RoleName;
@Column(name = "parent3_role_id")
private Long parent3RoleId;
@Column(name = "parent3_role_name", length = 50)
private String parent3RoleName;
@Column(name = "parent4_role_id")
private Long parent4RoleId;
@Column(name = "parent4_role_name", length = 50)
private String parent4RoleName;
@Column(name = "parent5_role_id")
private Long parent5RoleId;
@Column(name = "parent5_role_name", length = 50)
private String parent5RoleName;
@Column(name = "parent6_role_id")
private Long parent6RoleId;
@Column(name = "parent6_role_name", length = 50)
private String parent6RoleName;
@Column(name = "parent7_role_id")
private Long parent7RoleId;
@Column(name = "parent7_role_name", length = 50)
private String parent7RoleName;
@Column(name = "parent8_role_id")
private Long parent8RoleId;
@Column(name = "parent8_role_name", length = 50)
private String parent8RoleName;
@Column(name = "parent9_role_id")
private Long parent9RoleId;
@Column(name = "parent9_role_name", length = 50)
private String parent9RoleName;
@Column(name = "parent10_role_id")
private Long parent10RoleId;
@Column(name = "parent10_role_name", length = 50)
private String parent10RoleName;
@Column(name = "EMAIL", length = 50)
private String email;
@Column(name = "PARTY_TITLE", length = 10)
private String partyTitle;
@Column(name = "PARTY_NAME", length = 100)
private String partyName;
@Column(name = "CONTACT_NO", length = 15)
private String contactNo;
@Column(name = "ADDRESS_LINE1", length = 200)
private String addressLine1;
@Column(name = "CITY", length = 20)
private String city;
@Column(name = "STATE", length = 20)
private String state;
@Column(name = "LOCATION_ID")
private Long locationId;
@Column(name = "PARTY_START_DATE", length = 23)
@Temporal(javax.persistence.TemporalType.DATE)
private Date partyStartDate;
@Column(name = "USER_GROUP_ID")
private Long userGroupId;
@Column(name = "user_group_name", length = 50)
private String userGroupName;

gettrs and setters....

我已经检查了sql server中hibernate创建的查询,并且工作正常但是在执行上面的条件时我得到以下异常 -

Hibernate: select this_.ID as ID11_0_, this_.USER_ID as USER2_11_0_, this_.ORG_UNIT_ID as ORG3_11_0_, this_.INTERNAL_FLAG as INTERNAL4_11_0_, this_.PARENT_USER_ID as PARENT5_11_0_, this_.ROLE_ID as ROLE6_11_0_, this_.DEPARTMENT as DEPARTMENT11_0_, this_.USER_LOCATION_ID as USER8_11_0_, this_.SCREEN_WIDTH as SCREEN9_11_0_, this_.SCREEN_HEIGHT as SCREEN10_11_0_, this_.COMMENTS as COMMENTS11_0_, this_.REV_REF_ID as REV12_11_0_, this_.REVISION_NO as REVISION13_11_0_, this_.ACTIVE_FLAG as ACTIVE14_11_0_, this_.START_DATE as START15_11_0_, this_.END_DATE as END16_11_0_, this_.CREATED_BY as CREATED17_11_0_, this_.CREATION_DATE as CREATION18_11_0_, this_.UPDATED_BY as UPDATED19_11_0_, this_.UPDATE_DATE as UPDATE20_11_0_, this_.APPROVAL_LIMIT as APPROVAL21_11_0_, this_.user_name as user22_11_0_, this_.role_name as role23_11_0_, this_.Org_Type_Name as Org24_11_0_, this_.ORG_UNIT_TYPE as ORG25_11_0_, this_.PARTY_TYPE as PARTY26_11_0_, this_.ORG_UNIT_NAME as ORG27_11_0_, this_.Dept_Name as Dept28_11_0_, this_.parent_party_name as parent29_11_0_, this_.Party_id as Party30_11_0_, this_.Party_Full_Name as Party31_11_0_, this_.LOCATION_NAME as LOCATION32_11_0_, this_.Loc_Type_Name as Loc33_11_0_, this_.LOCATION_TYPE as LOCATION34_11_0_, this_.parent1_id as parent35_11_0_, this_.parent1_loc_name as parent36_11_0_, this_.parent1_loc_type as parent37_11_0_, this_.parent2_id as parent38_11_0_, this_.parent2_loc_name as parent39_11_0_, this_.parent2_loc_type as parent40_11_0_, this_.parent3_id as parent41_11_0_, this_.parent3_loc_name as parent42_11_0_, this_.parent3_loc_type as parent43_11_0_, this_.parent4_id as parent44_11_0_, this_.parent4_loc_name as parent45_11_0_, this_.parent4_loc_type as parent46_11_0_, this_.parent5_id as parent47_11_0_, this_.parent5_loc_name as parent48_11_0_, this_.parent5_loc_type as parent49_11_0_, this_.parent_role_id as parent50_11_0_, this_.Parent_Role_Name as Parent51_11_0_, this_.ORG_ADDRESS as ORG52_11_0_, this_.parent1_role_id as parent53_11_0_, this_.parent1_role_name as parent54_11_0_, this_.parent2_role_id as parent55_11_0_, this_.parent2_role_name as parent56_11_0_, this_.parent3_role_id as parent57_11_0_, this_.parent3_role_name as parent58_11_0_, this_.parent4_role_id as parent59_11_0_, this_.parent4_role_name as parent60_11_0_, this_.parent5_role_id as parent61_11_0_, this_.parent5_role_name as parent62_11_0_, this_.parent6_role_id as parent63_11_0_, this_.parent6_role_name as parent64_11_0_, this_.parent7_role_id as parent65_11_0_, this_.parent7_role_name as parent66_11_0_, this_.parent8_role_id as parent67_11_0_, this_.parent8_role_name as parent68_11_0_, this_.parent9_role_id as parent69_11_0_, this_.parent9_role_name as parent70_11_0_, this_.parent10_role_id as parent71_11_0_, this_.parent10_role_name as parent72_11_0_, this_.EMAIL as EMAIL11_0_, this_.PARTY_TITLE as PARTY74_11_0_, this_.PARTY_NAME as PARTY75_11_0_, this_.CONTACT_NO as CONTACT76_11_0_, this_.ADDRESS_LINE1 as ADDRESS77_11_0_, this_.CITY as CITY11_0_, this_.STATE as STATE11_0_, this_.LOCATION_ID as LOCATION80_11_0_, this_.PARTY_START_DATE as PARTY81_11_0_, this_.USER_GROUP_ID as USER82_11_0_, this_.user_group_name as user83_11_0_ from STD_ORG_USERS_V this_ where this_.PARTY_TYPE=?
Hibernate: select this_.ID as ID11_0_, this_.USER_ID as USER2_11_0_, this_.ORG_UNIT_ID as ORG3_11_0_, this_.INTERNAL_FLAG as INTERNAL4_11_0_, this_.PARENT_USER_ID as PARENT5_11_0_, this_.ROLE_ID as ROLE6_11_0_, this_.DEPARTMENT as DEPARTMENT11_0_, this_.USER_LOCATION_ID as USER8_11_0_, this_.SCREEN_WIDTH as SCREEN9_11_0_, this_.SCREEN_HEIGHT as SCREEN10_11_0_, this_.COMMENTS as COMMENTS11_0_, this_.REV_REF_ID as REV12_11_0_, this_.REVISION_NO as REVISION13_11_0_, this_.ACTIVE_FLAG as ACTIVE14_11_0_, this_.START_DATE as START15_11_0_, this_.END_DATE as END16_11_0_, this_.CREATED_BY as CREATED17_11_0_, this_.CREATION_DATE as CREATION18_11_0_, this_.UPDATED_BY as UPDATED19_11_0_, this_.UPDATE_DATE as UPDATE20_11_0_, this_.APPROVAL_LIMIT as APPROVAL21_11_0_, this_.user_name as user22_11_0_, this_.role_name as role23_11_0_, this_.Org_Type_Name as Org24_11_0_, this_.ORG_UNIT_TYPE as ORG25_11_0_, this_.PARTY_TYPE as PARTY26_11_0_, this_.ORG_UNIT_NAME as ORG27_11_0_, this_.Dept_Name as Dept28_11_0_, this_.parent_party_name as parent29_11_0_, this_.Party_id as Party30_11_0_, this_.Party_Full_Name as Party31_11_0_, this_.LOCATION_NAME as LOCATION32_11_0_, this_.Loc_Type_Name as Loc33_11_0_, this_.LOCATION_TYPE as LOCATION34_11_0_, this_.parent1_id as parent35_11_0_, this_.parent1_loc_name as parent36_11_0_, this_.parent1_loc_type as parent37_11_0_, this_.parent2_id as parent38_11_0_, this_.parent2_loc_name as parent39_11_0_, this_.parent2_loc_type as parent40_11_0_, this_.parent3_id as parent41_11_0_, this_.parent3_loc_name as parent42_11_0_, this_.parent3_loc_type as parent43_11_0_, this_.parent4_id as parent44_11_0_, this_.parent4_loc_name as parent45_11_0_, this_.parent4_loc_type as parent46_11_0_, this_.parent5_id as parent47_11_0_, this_.parent5_loc_name as parent48_11_0_, this_.parent5_loc_type as parent49_11_0_, this_.parent_role_id as parent50_11_0_, this_.Parent_Role_Name as Parent51_11_0_, this_.ORG_ADDRESS as ORG52_11_0_, this_.parent1_role_id as parent53_11_0_, this_.parent1_role_name as parent54_11_0_, this_.parent2_role_id as parent55_11_0_, this_.parent2_role_name as parent56_11_0_, this_.parent3_role_id as parent57_11_0_, this_.parent3_role_name as parent58_11_0_, this_.parent4_role_id as parent59_11_0_, this_.parent4_role_name as parent60_11_0_, this_.parent5_role_id as parent61_11_0_, this_.parent5_role_name as parent62_11_0_, this_.parent6_role_id as parent63_11_0_, this_.parent6_role_name as parent64_11_0_, this_.parent7_role_id as parent65_11_0_, this_.parent7_role_name as parent66_11_0_, this_.parent8_role_id as parent67_11_0_, this_.parent8_role_name as parent68_11_0_, this_.parent9_role_id as parent69_11_0_, this_.parent9_role_name as parent70_11_0_, this_.parent10_role_id as parent71_11_0_, this_.parent10_role_name as parent72_11_0_, this_.EMAIL as EMAIL11_0_, this_.PARTY_TITLE as PARTY74_11_0_, this_.PARTY_NAME as PARTY75_11_0_, this_.CONTACT_NO as CONTACT76_11_0_, this_.ADDRESS_LINE1 as ADDRESS77_11_0_, this_.CITY as CITY11_0_, this_.STATE as STATE11_0_, this_.LOCATION_ID as LOCATION80_11_0_, this_.PARTY_START_DATE as PARTY81_11_0_, this_.USER_GROUP_ID as USER82_11_0_, this_.user_group_name as user83_11_0_ from STD_ORG_USERS_V this_ where this_.PARTY_TYPE=?
org.hibernate.exception.DataException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2214)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:305)
at WF.workflow.getUsersVikas(workflow.java:547)
at org.apache.jsp.MARICON.ParentUser_jsp._jspService(ParentUser_jsp.java:149)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: The value supplied cannot be converted to BIGINT.
at net.sourceforge.jtds.jdbc.Support.convert(Support.java:653)
at net.sourceforge.jtds.jdbc.JtdsResultSet.getLong(JtdsResultSet.java:645)
at net.sourceforge.jtds.jdbc.JtdsResultSet.getLong(JtdsResultSet.java:972)
at org.hibernate.type.LongType.get(LongType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2046)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1371)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1299)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
... 30 more

请帮忙。

1 个答案:

答案 0 :(得分:4)

我建议你根据你在bean中声明的列来验证列的类型,因为它似乎存在类型转换问题。

Caused by: java.sql.SQLException: The value supplied cannot be converted to BIGINT.

我注意到有些字段有long,有些是Long;应该没问题。但是使用原语或引用是很好的;但不是混合。

作为快速检查,我建议您检查retrieving all是否有效。

hsSession.createQuery("from StdOrgUsersV").list()

如果上述查询也导致同样的问题,那么它显然是一个数据类型问题;不是由于Criteria