Announcement Announcement Module
Collapse
No announcement yet.
External application updates database, hibernate is not synchronized Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • External application updates database, hibernate is not synchronized

    Hi,

    Can someone help me about this simple but tricky problem fir me.

    Overview:
    I have an application 1 that runs hibernate, a second application 2(external application) that updates the database.

    Problem:
    When Application 2(external application) updates the database, the Application 1(the one uses hibernate) is not updated or synchronised. How do i get away with this problem so that Application 1(hibernate) is also synchronsied to database when Application 2(external application) updates the database.

    Thank you guys

  • #2
    Hello

    Could you post your actual configuration?, I think this theme is more related with Hibernate and DB configuration

    When Application 2(external application) updates the database, the Application 1(the one uses hibernate) is not updated or synchronised.
    How you got such conclusion?

    Question: Application 1 and 2 access the same DB?

    Comment


    • #3
      Originally posted by dr_pompeii View Post
      Hello

      Could you post your actual configuration?, I think this theme is more related with Hibernate and DB configuration


      How you got such conclusion?

      Question: Application 1 and 2 access the same DB?

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
      <hibernate-configuration>
      <session-factory>
      <property name="hibernate.dialect">org.hibernate.dialect.MyS QLDialect</property>
      <property name="hibernate.connection.driver_class">com.mysql .jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/xxxx</property>
      <property name="hibernate.connection.username">xxxxx</property>
      <property name="hibernate.connection.password">xxxxx</property>
      <property name="hibernate.show_sql">true</property>
      <property name="hibernate.current_session_context_class">thr ead</property>
      <property name="hibernate.query.factory_class">org.hibernate .hql.classic.ClassicQueryTranslatorFactory</property>
      <property name="hibernate.connection.autocommit">true</property>
      <mapping resource="xxx/AdvertismentStatus.hbm.xml"/>
      <mapping resource="xxx/Industry.hbm.xml"/>
      <mapping resource="xxx/Branch.hbm.xml"/>
      <mapping resource="xxx/Advertisement.hbm.xml"/>
      <mapping resource="xxx/Customers.hbm.xml"/>
      <mapping resource="xxx/State.hbm.xml"/>
      </session-factory>
      </hibernate-configuration>



      /*
      * To change this template, choose Tools | Templates
      * and open the template in the editor.
      */
      package com.proxiwoo.db.util;

      import org.hibernate.Session;
      import org.hibernate.cfg.AnnotationConfiguration;
      import org.hibernate.SessionFactory;

      /**
      * Hibernate Utility class with a convenient method to get Session Factory object.
      *
      * @author truffles
      */
      public class HibernateUtil {

      private static final SessionFactory sessionFactory;
      private static Session session = null;

      static {
      try {
      sessionFactory = new AnnotationConfiguration().configure().buildSession Factory();
      } catch (Throwable ex) {
      // Log the exception.
      System.err.println("Initial SessionFactory creation failed." + ex);
      throw new ExceptionInInitializerError(ex);
      }
      }

      public static SessionFactory getSessionFactory() {
      return sessionFactory;
      }

      public static Session getCurrentSession() {
      if(session == null) {
      synchronized(HibernateUtil.class) {
      if(session == null)
      session = HibernateUtil.getSessionFactory().getCurrentSessio n();
      }
      }
      else if(session.isOpen() == false) {
      synchronized(HibernateUtil.class) {
      if(session.isOpen() == false)
      session = HibernateUtil.getSessionFactory().getCurrentSessio n();
      }
      }
      return session;
      }


      /*
      public static Session getCurrentSession() {
      return HibernateUtil.getSessionFactory().openSession();
      }
      *
      */
      }
      Last edited by lightyear; Aug 17th, 2011, 08:18 AM. Reason: added info

      Comment


      • #4
        Hello

        1) use code tags, is more readable for us
        2) Are you working with Spring to? If not, forward to post your problem to Hibernate Forum
        3) In your code where is the code that should be aware automatically about the changes done by the 2 Application?

        Again I do the question

        When Application 2(external application) updates the database, the Application 1(the one uses hibernate) is not updated or synchronised.
        How you got such conclusion?

        And again

        Question: Application 1 and 2 access the same DB?

        Comment


        • #5
          Application 1 and 2 access the same db.

          If application 2 updates the table that application 1 is using, the application 1 that uses hibernate does not see the changes in database when i retrieve data.

          Comment


          • #6
            Application 1 and 2 access the same db.
            OK

            If application 2 updates the table that application 1 is using, the application 1 that uses hibernate does not see the changes in database when i retrieve data.
            I think has no sense, Application 1 should not be worry nor aware about application 2, since both share the same DB

            Comment


            • #7
              hibernate is caches data. it is not synchronized to db if external application updates it. is there away that it refreshes its persistence?

              Comment

              Working...
              X