mysql - 休眠异常:从 mysql 迁移到 oracle 11g db 时
问题描述
我正在尝试将我的应用程序数据库从 mysql 更改为 oracle 11g。我在这个应用程序中使用休眠,但休眠正在抛出:
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2231)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1722)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)
下面是我的 hibernate.cfg.xml 文件:
*<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- <property name="hibernate.default_schema">wind</property> -->
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">validate</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property>
<!-- <property name="connection.autoReconnect">true</property> -->
<!-- <property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">100</property>-->
<property name="hibernate.c3p0.timeout">25200</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>*
我正在为数据库 url 和 id 密码使用一个配置文件。
DATABASE_URL=jdbc:oracle:thin:@localhost:1521/wind
DATABASE_USERNAME=appuser
DATABASE_PASSWORD=appuser
DATABASE_CONN_POOL_MIN=5
DATABASE_CONN_POOL_MAX=50
映射文件:
<hibernate-mapping>
<class name="com.nsn.abc.entity.UserInfo" table="user_info" >
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned" />
</id>
<property name="username" type="string">
<column name="username" length="30" not-null="true" unique="true" />
</property>
<property name="firstName" type="string">
<column name="first_name" length="30" not-null="true" />
</property>
<property name="lastname" type="string">
<column name="lastname" length="30" />
</property>
<property name="email" type="string">
<column name="email" length="50" />
</property>
<property name="password" type="string">
<column name="password" length="30" not-null="true" />
</property>
<property name="phoneNumber" type="string">
<column name="phone_number" length="30" />
</property>
<property name="rights" type="string">
<column name="rights" length="30" not-null="true" />
</property>
<property name="counter" type="int">
<column name="counter" not-null="true" />
</property>
<property name="role" type="string">
<column name="role" length="20" />
</property>
<property name="activeFlag" type="boolean">
<column name="active_flag" not-null="true" />
</property>
<property name="info" type="string">
<column name="info" length="45" />
</property>
<set name="massProvisioningHistories" table="mass_provisioning_history" inverse="true" lazy="true" fetch="select">
<key>
<column name="user_ref" not-null="true" />
</key>
<one-to-many class="com.nsn.abc.entity.MassProvisioningHistory" />
</set>
</class>
</hibernate-mapping>
我检查了所有配置和其他细节,但仍然没有进展。它抛出SQL Error: 923, SQLState: 42000。使用 ORA-00923: FROM 关键字未在预期的位置找到 在日志中生成以下查询: 休眠:选择 userinfo0_.id 作为 id25_,userinfo0_.username 作为 username25_,userinfo0_.first_name 作为 first3_25_,userinfo0_.lastname 作为 lastname25_,userinfo0_.email 作为email25_, userinfo0_.password 作为 password25_, userinfo0_.phone_number 作为 phone7_25_, userinfo0_.rights 作为 rights25_, userinfo0_.counter 作为 counter25_, userinfo0_.role 作为 role25_, userinfo0_.active_flag 作为 active11_25_, userinfo0_.info 作为 info25_ from user_info userinfo0_ where userinfo0_.username =?
请建议。
问候, skr
解决方案
在应用程序中,我们使用 SELECT 1 来检查休眠连接。
MySql 支持“SELECT 1”,但在 oracle 中我们需要提及“SELECT 1 from dual”。
现在它工作正常。
感谢帮助。
推荐阅读
- python - 如何在按下和释放鼠标时存储鼠标位置?
- mediawiki - AD 组授权 - 用户未授权
- powerbi - Power BI - 计算客户运行逾期余额
- javascript - React native - 使用 android studio 编译包
- c++ - OpenCL 内核计时测量 0 秒或导致 SIGABRT
- google-apps-script - Google Script,for循环在达到其条件之前停止,导致它无法继续通过未检查的数据
- javascript - useEffect 缺少依赖项,但是当我添加它时,出现“超出最大更新深度”错误
- github - 如何使用 Jekyll 在 Github 页面中使用 font awesome
- python - 打字!带有 pyautogui 的字符
- java - Scrollbar in Javafx in not scrolling