3 Replies Latest reply on Jun 8, 2012 2:06 AM by 793912

    Multiple applications edit single database but JPA does not reflect changes

      Hello all,

      I have a very trouble some problem. I have a database which is access by several applications. And in one application(web) I use JPA. Everything worked fine so far.

      But recently I had to create another application(standalone) which access to same database and do edit/updates.

      My problem is, these updates does not reflect in web(JPA) application. I use a named query for search some records. Even updates are there jpa does not show these updates until I restart the glassfish server.

      I have tried many suggestions like cache clearance and nothing helped me. So I am post this question.

      My code
      // Search operation looks like following
      EntityManager entityManager = Persistence.createEntityManagerFactory("ModelPU");
      EntityTransaction entityTransaction = entityManager.getTransaction();
      Query queryPatientNotifications = entityManager.createNamedQuery("Course.getAllNotifications");
      queryPatientNotifications.setParameter("cId", id);
      Course course = (Course) queryPatientNotifications.getResultList().get(0);
      List<CourseSMSNotification> allNotifications = course.getNotifications();
      System.out.println("Not Size :" + allNotifications.size()); // PROBLEM : print 0 even there are records in database
      Persistance unit
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
        <persistence-unit name="CosmicTBModelPU" transaction-type="RESOURCE_LOCAL">
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/DB_TB"/>
            <property name="javax.persistence.jdbc.password" value=""/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
      Can some one please help me with this?

      Thank you