Hibernate不包含模式到查询中

时间:2017-07-25 14:28:02

标签: java oracle hibernate schema oracle-sqldeveloper

根据配置,Hibernate DAO存储库应该发送如下查询:

INSERT INTO some_schema.some_table (...) VALUES (...)

相反,Hibernate发送了这个:

INSERT INTO some_table (...) VALUES (...)

省略了架构前缀。没有该前缀我得到ORA-00942,表不存在Oracle数据库错误。如何强制Hibernate发送模式前缀?

P.S。此问题类似于GNU C library docs,但添加默认架构对我不起作用,因为我使用了更多这些架构。

实体配置如下:

<hibernate-mapping>
<class name="com.somepackage.SomeClass" table="some_table" schema="some_schema">
  <id name="someID" type="int" column="SOME_TABLE_ID">
     <generator class="increment"/>
  </id>
  <property name="someProp" column="SOME_PROP" type="string"/>
</class>
</hibernate-mapping>

Hibernate配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!-- Oracle data source definition -->
<bean id="oracleDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName"><value>${oracle.database.driverClassName}</value></property>
    <property name="url"><value>${oracle.database.url}</value></property>
    <property name="username"><value>${oracle.database.username}</value></property>
    <property name="password"><value>${oracle.database.password}</value></property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="oracleDataSource" />
    <property name="mappingResources">
        <list>
            <value>some-table.cfg.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.current_session_context_class">thread</prop>
        </props>
    </property>
</bean>

1 个答案:

答案 0 :(得分:2)

在hibernate属性中添加以下内容。它应该被自动挑选。我有同样的工作

firstPipe.groovy