EndlessLeaves 2016-08-18 12:03 采纳率: 0%
浏览 1178

SSH整合中,HQL查询问题

[color=#FF0000][b]软件环境配置:[/b][/color]Spring2.5+struts2.1+Hibernate3.1+oracle11g

[color=#FF0000][b]问题:[/b][/color]
一个查询的方法,通过hql拼接实现动态查询。在实现按编号查询的时候出现了这样的奇葩问题。。。。
数据库里编号是主键,varchar类型,持久化类对应字段String类型,编号如:0101,0102,0103....0205,0306
在查询0108和0109时报错,其余正常。。。单元测试和tomcat中是一样的结果。不能查询0108和0109。

[b][color=#FF0000]以下是查询 0109 时控制台报错:[/color][/b]
图片说明
[b][color=#FF0000]以下是查询 0107 时控制的查询结果:[/color][/b]
图片说明
[b][color=#FF0000]查询0107时,自动生成的sql代码:[/color][/b]
SQL: select rooms0_.ID as col_0_0_, types1_.NAME as col_1_0_, types1_.ROOMSIZE as col_2_0_, types1_.DPRICE as col_3_0_, types1_.HPRICE as col_4_0_, types1_.DEPOSIT as col_5_0_ from ADMIN5.ROOMS rooms0_, ADMIN5.TYPES types1_ where rooms0_.TYPE_ID=types1_.ID and rooms0_.STATE=1 and rooms0_.ID=[size=18px][color=#FF0000]107[/color][/size] order by types1_.ID, rooms0_.ID

[color=#0000FF][size=24px]这里自动转化成了107????为什么啊???那为什么查询0109和0108不自动转换呢?反而说session已经关闭???[/size][/color]

[color=#FF0000][b]java代码:[/b][/color]

[img=http://img.bbs.csdn.net/upload/201608/18/1471518802_118168.png][/img]

[b][color=#FF0000]Spring(代理了hibernate的sessionFactory)代码:[/color][/b]
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd ">

<bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"
        value="oracle.jdbc.driver.OracleDriver">
    </property>
    <property name="url"
        value="jdbc:oracle:thin:@localhost:1521:ORCL">
    </property>
    <property name="username" value="xxxxxxx"></property>
    <property name="password" value="xxxxxxx"></property>
</bean>
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.Oracle9Dialect
            </prop>
        </props>
    </property>
    <property name="mappingResources">
        <list>
            <value>com/accp/entity/Checkin.hbm.xml</value>
            <value>com/accp/entity/Rooms.hbm.xml</value>
            <value>com/accp/entity/Admin.hbm.xml</value>
            <value>com/accp/entity/Reserve.hbm.xml</value>
            <value>com/accp/entity/Types.hbm.xml</value>
            <value>com/accp/entity/Orders.hbm.xml</value></list>
    </property></bean>

<!-- 自动扫描包 -->
<context:component-scan base-package="com.xxx"></context:component-scan>

<!-- 引入事务管理器类 -->
<bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="tranManger">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- 事务注解 -->
<tx:annotation-driven transaction-manager="tranManger"/>

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-10-03 16:42
    关注

    #FF0000][b]软件环境配置:[/b][/color]Spring2.5+struts2.1+Hibernate3.1+oracle11g
    [color=#FF0000][b]问题:[/b][/color]
    一个查询的方法,通过hql拼接实现动态查询。在实现按编号查询的时候出现了这样的奇葩问题。。。。
    数据库里编号是主键,varchar类型,持久化类对应字段String类型,编号如:0101,0102,0103....0205,0306
    在查询0108和0109时报错,其余正常。。。单元测试和tomc

    评论

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿