0

I am working on a Spring-MVC application which we have running on 2 servers, one is our testing server, 2nd one is our live server. Is there any way that I can configure Hibernate to write any and all DB related queries on both servers. Example : User A saved Object A on live server, then write the same object on Test-server, vice-versa is not required. Our test and live server both have same setting and same database. Thank you.

root-context.xml :

   <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
                destroy-method="close">
        <beans:property name="driverClassName" value="org.postgresql.Driver"/>
        <beans:property name="url"
                        value="jdbc:postgresql://localhost:PORT/DB_NAME"/>
        <beans:property name="username" value="USERNAME"/>
        <beans:property name="password" value="PASSWORD"/>
        <beans:property name="removeAbandoned" value="true"/>
        <beans:property name="removeAbandonedTimeout" value="20"/>
        <beans:property name="defaultAutoCommit" value="false"/>
    </beans:bean>

    <!-- Hibernate 4 SessionFactory Bean definition -->
    <beans:bean id="hibernate4AnnotatedSessionFactory"
                class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <beans:property name="dataSource" ref="dataSource"/>
        <beans:property name="packagesToScan" value="com.tooltank.spring.model"/>
        <beans:property name="hibernateProperties">
            <beans:props>
                <beans:prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</beans:prop>
                <beans:prop key="hibernate.show_sql">false</beans:prop>
                <!--   <beans:prop key="hibernate.jdbc.batch_size">1000</beans:prop>-->
                <beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop>
                <beans:prop key="cache.use_second_level_cache">true</beans:prop>
                <beans:prop key="cache.use_query_cache">true</beans:prop>
                <beans:prop key="hibernate.order_updates">true</beans:prop>
                <beans:prop key="show_sql">false</beans:prop>
            </beans:props>
        </beans:property>

    </beans:bean>

   <hibernate.version>4.3.9.Final</hibernate.version>

If anymore data is required, please let me know. Thank you.

6
  • Consider also migrating this question to Database Administrators or rewrite it and ask there as a new. Commented Oct 26, 2017 at 9:08
  • @pirho : How do I migrate a question? It says that it can be migrated by a close vote, unable to see any option regarding that. Thank you. Commented Oct 26, 2017 at 10:41
  • Mind if i try? You propably then need/want to register DA and maybe edit question there. Commented Oct 26, 2017 at 10:45
  • @pirho : I am already registered. Thank you. Commented Oct 26, 2017 at 10:47
  • Done. Now just wait for moderator reaction. btw it is flag->should be closed->off topic->belongs to another site. Maybe those are not visible to OP. Commented Oct 26, 2017 at 10:50

1 Answer 1

1

Not in any way that you're probably hoping for. They have completely different transactional contexts, so you can't just pretend that 2 databases are one.

What if one database throws an exception and the other one doesn't? Did the tx commit or roll back? Hibernate certainly doesn't expect it to be "half success".

You could make the test server a slave of the live server and just write to the live server. This is not a simple solution either and can be outright stupid.

Sign up to request clarification or add additional context in comments.

5 Comments

Any other way via PostgreSQL? THanks
That would be the master-slave thing.
@We are Borg Maybe PgCluster?
@pirho Their homepage says their latest version 1.9 is still based on PSQL-8.3 I am running 9.6. pgfoundry.org/forum/forum.php?forum_id=1618 . Am I correct to assume 8.3 is PostgreSQL version? Thanks.
@We are Borg not sure about that. But there are some articles which - depending on your environmet - might help, just for example like this for ubuntu 16.04. Some searching might help. Then visit also Database Administrators.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.