-->
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: Inserted Object is not being cached
PostPosted: Thu Feb 05, 2009 11:18 pm 
Newbie

Joined: Sun Oct 05, 2008 2:45 pm
Posts: 8
Hi,

I persist a new object into database through Stateless / Stateful EJB (tried with both of them), and then try to select all objects through cacheable query, it does not retrieve objects from the cache. But if i do not insert anything and just select, everything works fine. I use JBoss Cache for L2 caching, is it a normal behavior?

Here is the code i use.

Code:
@NamedQueries({@NamedQuery(query = "from Event",
                           name = "Event.findAll",                               
                           hints = {@QueryHint(name = "org.hibernate.cacheable", value = "true"),
                                    @QueryHint(name="org.hibernate.cacheRegion", value = "EventRegion")                                   
                                   }
                           )
               }
              )
@Entity
@Table(name = "EVENT")
@Cache (usage=CacheConcurrencyStrategy.TRANSACTIONAL)
public class Event implements Serializable {
..
..
}


Methods in EJB
Code:
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public Event persist(Event event) {
        em.persist(event);
        return event;
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public List<Event> findAllByRange(int start, int max) {
        Query q = em.createNamedQuery("Event.findAll"); 
        q.setFirstResult(start);
        q.setMaxResults(max);
       
        return q.getResultList();
    }



And the test code:

Code:
        EventBean eventBean = new EventBean();               
        Event event = new Event();
        event.setOwner(user);
        event.setMessage(message);       
        event = eventBean.persist(event);
       
        List<Event> eventList = eventBean.findAllByRange(0, 15);


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 08, 2009 5:41 am 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
It's my understanding that the query cache will automatically detect when items that could effect the query's results are inserted or deleted and expire as a result.

So, if I understand your post correctly, doesn't it make sense that the query cache is no longer valid after you have inserted a new object?


--
Stephen Souness


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 08, 2009 5:30 pm 
Newbie

Joined: Sun Oct 05, 2008 2:45 pm
Posts: 8
Hi,

I expected it to automatically adds the persisted objects into query cache result and give me the updated one. How can i achieve it, do i need to manage the cache by my own?

Thanks.


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.