users@glassfish.java.net

Persisting entities makes it to db table but on next retrieve is not found...

From: <forums_at_java.net>
Date: Wed, 1 Feb 2012 02:37:43 -0600 (CST)

Hi all,

I've been seeing this issue in just about all of my entity usage when storing
data and trying to retireve it again. I can't seem to find out why this
happens. As an example, I have a profile page that a user filles out some
info, hits submit, and I persist the incoming form data. This creates a new
user. I use the em.persist(obj); em.flush(); and even without flush() it
often shows up in the mysql DB immediately (mysql 5.1 on a linux server).
After the creation and verifying it's in the DB, I click the logout button
which invalidtes the user session (httpsession). I then log in again.
I should say this is part of a @OneToMany mapping with the join on the
@ManyToOne side of the object. I do persist the object AND add it to the
OneToMany collection as well. So after the login, the persisted data does not
show up. If I log out, then log back in a 2nd time, it now shows up. I've
tried any number of things to figure out why this may happen. I've put the
Cascade type to all, persist, merge, refresh, etc. I've also set the
@OneToMany to eager load. Nothing seems to work. I don't want eager load
anyway, but that doesn't seem to force it. To fetch it, I use the @OneToMany
object to call the getXxx method that should retreive the collection. If it's
lasy loaded, the first get should load it at that point.

I've seen this in a number of areas of my code with similar code.. onetomany
and such. I've followed a couple of EJB books but typically they don't
explain this scenario.. or how or why some data may not show up right after
persisting it but later it will work. I can't seem to find a good source of
info on issues like this, and dealing with async methods, threading, and
scalability with regards to JEE6 in general. Seems not many know about this.

Thanks for any help.


--
[Message sent by forum member 'andjarnic']
View Post: http://forums.java.net/node/883181