-->
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.  [ 2 posts ] 
Author Message
 Post subject: EntityManager.find() unable to find the updated Entity
PostPosted: Sun Mar 27, 2016 12:39 pm 
Newbie

Joined: Sun Mar 27, 2016 12:26 pm
Posts: 2
Env:
WildFly 10.0.0.Final
Hibernate 5.0.7.Final

Hi,

In my web application, i have following code

Stateless Session Bean
Code:
  @Inject
  private EmployeeRepostiory repo;

  public Employee checkChanges() {
    return repo.get();
  }


and the EmployeeRepository class
Code:
  @PersistenceContext(name = "employees")
  private EntityManager em;

  public Employee get() {

    Employee o1 = em.find(Employee.class, 1);
    o1.setFirstName("test");
    Employee o2 = em.find(Employee.class, 1);

    return o1;
  }


The transaction attribute is default i.e. MANDATORY. The FlushMode is AUTO (verified that)

Issue: For some reason, the second find() method still gets the data from DB. It is unable to get the updated employee record that is still present in the Entity Context.

Any inputs are much appreciated.

Rakesh


Top
 Profile  
 
 Post subject: Re: EntityManager.find() unable to find the updated Entity
PostPosted: Thu Mar 31, 2016 3:26 am 
Newbie

Joined: Sun Mar 27, 2016 12:26 pm
Posts: 2
How stupid of me! Forgot to mark the bean with @Stateless. All along it was just a RESTful bean doing its diligent work without transaction. While debugging hibernate code noticed that transaction was in fact not present.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.