1

According to configuration, Hibernate DAO repository should send query like this:

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

Instead, Hibernate sends this:

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

It omits schema prefix. Without that prefix I am getting ORA-00942, table does not exist Oracle database error. How to force Hibernate send schema prefix?

P.S. This question is similar to this question, but adding default schema doesn't work for me, because I am using more of them.

Configuration of entity is like this:

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

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

milosdju
  • 783
  • 12
  • 27

1 Answers1

2

Add the below in your hibernate properties. It should automatically be picked. I have the same and it works

<property name="hibernate.default_schema" value="myschema"/>
user8271644
  • 219
  • 2
  • 8
  • Also found the below link which refers to the same question https://stackoverflow.com/questions/2737420/how-to-set-up-default-schema-name-in-jpa-configuration – user8271644 Jul 25 '17 at 14:33
  • 1
    Thanks for answer! But I shouldn't set default_schema because application will in some moment use more schema's. – milosdju Jul 25 '17 at 15:04
  • Have no experience with that but did some search and came up with the below link , see if that helps you https://stackoverflow.com/questions/398215/how-can-i-set-the-schema-name-used-by-hibernate-entities-at-query-time – user8271644 Jul 25 '17 at 15:13