Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Hibernate schema changes

I am new to Hibernate and am having some issue with its configuration. I am trying to setup a read-only connection to a preexisting Oracle database. I do not want Hibernate to execute any DML/DDL and alter the database schema, yet every time I try deploying my project, this is the message I see:

INFO: updating schema
SEVERE: Unsuccessful: create table WILLOEM.SAMPLE_INFO (SAMPLE_ID varchar2(255) not null, CELL_LINE varchar2(255), STUDY_ID varchar2(255), primary key (SAMPLE_ID))
SEVERE: ORA-00955: name is already used by an existing object

No damage is being done here, since the table creation failed, but I don't want to create a situation where data can be lost. How can I configure Hibernate to act in a read-only manner? Can I prevent statement execution completely, without adding a new Oracle user that lacks the privileges?

Here is my current Hibernate configuration:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName"><value>oracle.jdbc.OracleDriver</value></property>
    <property name="url"><value>jdbc:oracle:thin:@source.db.somewhere.com:1524:WILLOEM</value></property>
    <property name="username"><value>username</value></property>
    <property name="password"><value>password</value></property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="packagesToScan" value="com.willoem.project.hibernate" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
like image 543
woemler Avatar asked Jan 14 '23 09:01

woemler


1 Answers

you could change

<prop key="hibernate.hbm2ddl.auto">update</prop>

to

<prop key="hibernate.hbm2ddl.auto">validate</prop>

this validates the schema, but it will not make any no changes to it.

like image 76
JustDanyul Avatar answered Jan 17 '23 05:01

JustDanyul