專門給用戶培訓的環境後台日志最近報出一個異常,
- org.hibernate.exception.SQLGrammarException: could not execute query
- at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
- at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
- at org.hibernate.loader.Loader.doList(Loader.java:2214)
- at com.cnpc.oms.dao.BaseHibernateDAO.pagedQuery(BaseHibernateDAO.java:280)
- ……
- Caused by: java.sql.SQLException: ORA-00907: 缺失右括號
-
- at Oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
- at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
- at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
- at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
- ... 38 more
取出hibernate後台日志打印的sql語句分析,出問題的這段sql語句為:
- select *
- from (select this_.SUB_ID as ACID1_1373_0_,
- ......
- this_.OPER_DATE as OPER19_1373_0_,
- (select t.well_name
- from BASE_WELL_INFO t
- where t.well_id =
- ((select t.well_id
- from SUPER_TABLE_1 t
- where t.ID = this_.TASK_ID
- and rownum = 1 this_.union
- select t.well_id
- from SUPER_TABLE_2 t
- where t.ID =
- this_.TASK_ID
- and rownum = 1 this_.union
- select t.well_id
- from SUPER_TABLE_3 t
- where t.ID =
- this_.TASK_ID
- and rownum = 1 this_.union
- select t.well_id
- from SUPER_TABLE_4 t
- where t.ID =
- this_.TASK_ID
- and rownum = 1
- ))
- and rownum = 1) as formula1982_0_,
- ......
- from SUB_TABLE this_)
- where rownum <= ?
Hibernate映射文件中這段sql是這樣記錄的
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
- <!--
- Mapping file autogenerated by MyEclipse Persistence Tools
- -->
- <hibernate-mapping>
- <class name="……" table="SUB_TABLE">
- <comment>…… </comment>
- <id name="subId" type="java.lang.String">
- <column name="SUB_ID" length="32" />
- <generator class="uuid.hex" />
- </id>
- ……
- <property name="wellName" type="java.lang.String">
- <formula>
- (select t.well_name
- from base_well_info t
- where t.well_id = ((select t.well_id
- from SUPER_TABLE_1 t
- where t. ID = TASK_ID
- and rownum = 1
- union
- select t.well_id
- from SUPER_TABLE_2 t
- where t. ID = TASK_ID
- and rownum = 1
- union
- select t.well_id
- from SUPER_TABLE_3 t
- where t. ID = TASK_ID
- and rownum = 1
- union
- select t.well_id
- from SUPER_TABLE_4 t
- where t.ID = TASK_ID
- and rownum = 1))
- and rownum = 1
- )
- </formula>
- </property>
- ……
- </class>
- </hibernate-mapping>