2017-07-25 46 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