2

I have weird behavior of inconsistent data returned from my DB when there are 150+ users connected to our Web-app.

My EJBs connect to MySQL through mostly Netbeans 7.0 generated code, customized a bit for re-usability. What happens is that every so often, a user receives (in the browser) data that is not what it should be. I.e. User is viewing the details of product A, but part of the data (some one-to-many relationship data) belong to a different product. We don't have this issue when less users are logged-in. It seems problems start to raise at about 150 users.

The EntityManager part of the code does only em.create(...), em.persist(...) or em.merge(...). There is no refresh() or flush(). I disabled the shared cache. I have no load balancing.

What/Where could I look more?

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
JScoobyCed
  • 10,203
  • 6
  • 34
  • 58

1 Answers1

4

It depends on your situation.

But for your information in case you want to use those methods:

refresh() updates the entity with the data in the database table.

flush() does the exactly opposite, saves the values in the entity to the database table.

But since you are using EJBs, if you are using CMP then by default all the methods in an EJB run in a transaction (unless the transaction attributes are provided to not use them). And the transaction begins with the method call and ends when the method is done. At the end it is committed, which means you don't need to call the flush(). But if you need to synchronize the database with the entity before the commit then you need to call the flush().

Other than that it really depends on what your requirement is.

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142