-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Getting "old" data from Hibernate
PostPosted: Fri Oct 18, 2013 3:59 am 
Newbie

Joined: Mon Sep 02, 2013 12:11 pm
Posts: 10
Hallo,

I discovered a strange behaviour with hibernate. I have a Web-Applikation with JSF and Primefaces, as ORM I use Hibernate 4.2.5.
In my Browser data of table were shown. I change a entry (firstData --> secondData) in a cell, the change was wrong so I renew data. Everything ok (firstData).
I change same entry(firstData --> thirdData), the change was wrong so I renew data. Hibernate give the data of my first change (secondData). There is value "secondData" instead of "firstData" in my table. This behaviour can occur after 3.,4.,5. .. relodaing. So its not always the same.
When Hibernate give back correct data (firstData), Hibernate make a call to database and not to Hibernate itself. But I want to use Hibenrate caching and not fetching data from database everytime.


Here are my abstract DAO:

Code:

@Stateless
@Local(IHibernateDAO.class)
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public abstract class CHibernateDAO<T> implements IHibernateDAO {

   
   private static final ThreadLocal<EntityManager> tl_EntityManager = new ThreadLocal<EntityManager>();
   
   private static final EntityManagerFactory obj_EntityManagerFactory;
   
   private Class<?> persistentClass;
   
   
   static
               {
         obj_EntityManagerFactory = Persistence.createEntityManagerFactory("Persistence");
      }


        public CHibernateDAO(Class<?> c)
       {
      persistentClass = c;
   }
   

   private static EntityManager getCurrentManger()
   {

         EntityManager obj_manager = null;
         
     obj_manager = (EntityManager)tl_EntityManager.get();
   if(obj_manager == null || !obj_manager.isOpen())
   {
      obj_manager = obj_EntityManagerFactory.createEntityManager();            
        tl_EntityManager.set(obj_manager);
     }
        }
   

   public List<T> findAll()
     {
      
      List<T> li_Return = null;
      
      CriteriaBuilder cb = getCurrentManger().getCriteriaBuilder();
          
      CriteriaQuery<T>  criteriaQuery = (CriteriaQuery<T>) cb.createQuery(persistentClass);
      Root<T> root = (Root<T>) criteriaQuery.from(persistentClass);   

      criteriaQuery.select(root);
         
      TypedQuery<T> typedQuery = getCurrentManger().createQuery(criteriaQuery);

      li_Return = typedQuery.getResultList();

       
      return li_Return;
   }
}



And my persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!-- Persistenz Descriptor zur Konfiguration -->
<persistence 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"
   version="2.0">

   <persistence-unit name="Persistence" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>

      <properties>         
         <!-- JDBC connection pool (use the built-in) -->
         
      <property name="hibernate.connection.url" value="jdbc:oracle:thin:..."/>
        <property name="hibernate.connection.username" value="..."/>
        <property name="hibernate.connection.password" value="..."/>
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
         
         <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
         <property name="hibernate.format_sql" value="true" />
         <property name="hibernate.show_sql" value="false" />
         <property name="hibernate.jdbc.batch_size" value="20" />
         <property name="hibernate.cache.use_query_cache" value="false" />
         <property name="hibernate.hbm2ddl.auto" value="update" />
         <property name="hibernate.cache.use_second_level_cache"
            value="false" />            
      </properties>
   </persistence-unit>
</persistence>


Hibernate should give me a proxy of real Object. But in my case it seems to get a reference with my changed entry.

Can you give me an hint?

Thanks a lot


Top
 Profile  
 
 Post subject: Re: Getting "old" data from Hibernate
PostPosted: Mon Oct 21, 2013 1:49 am 
Newbie

Joined: Mon Sep 02, 2013 12:11 pm
Posts: 10
Hey there,

has nobody an idea and can help me?
Please give me just a hint to look for...

THX


Top
 Profile  
 
 Post subject: Re: Getting "old" data from Hibernate
PostPosted: Wed Dec 04, 2013 8:54 am 
Newbie

Joined: Mon May 06, 2013 12:49 am
Posts: 1
use session.evict(obj)
or session.refresh(obj)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.