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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)