2017-07-25 85 views
0

根據配置,Hibernate的DAO庫應該把這樣的查詢:Hibernate不包括架構到查詢

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

相反,休眠發送此:

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

它省略了模式前綴。沒有那個前綴我得到ORA-00942,表不存在Oracle數據庫錯誤。如何強制Hibernate發送模式前綴?

P.S.此問題與this question類似,但添加默認模式對我無效,因爲我使用了更多的模式。實體

配置是這樣的:

<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> 

+0

請顯示您的休眠配置文件 –

+0

@SatishPahuja這裏是休眠配置。 – milosdju

回答

1

添加下面在Hibernate的屬性。它應該自動被選中。我有同樣的,它的作品

<property name="hibernate.default_schema" value="myschema"/> 
+0

同時發現下面的鏈接引用了相同的問題https://stackoverflow.com/questions/2737420/how-to-set-up-default-schema-name-in-jpa-configuration – user8271644

+0

謝謝你的回答!但是我不應該設置default_schema,因爲應用程序在某個時候會使用更多的模式。 – milosdju

+0

沒有經驗,但做了一些搜索,並提出了下面的鏈接,看看是否可以幫助你https://stackoverflow.com/questions/398215/how-can-i-set-the-schema-name-used逐休眠實體,在查詢時間 – user8271644