Featured post
java - One entityManger finds entity , the other does not -
i have strange behavior in program. have 2 classes (class login , creategame) have injected entitymanager in each using annotation
@persistencecontext(unitname="myunitpu") entitymanager entitymanger;
in point remove object called "user" database using entitymanger.remove(user) method in login class. business logic user can host , join games ( in same time) removing user entries in database games user has created removed , entries showing in games user has joined removed also.
after that, call function checks if user exists using method in login class
entitymanager.find(user)
which surprisingly enough, finds user. after call method in creategame class tries find user using again
entitymanger.find(user)
the entitymanger in class fails find user (which expected result user removed , it's not in database)
so question : why entitymanager in 1 class finds user (which wrong) other doesn't find it? has ever same problem?
ps : "bug" occurs when user has hosted game joined user (lets call him buser) , buser has made game joined current user.
game | host | clients game1 | user | userb game2 | userb | user
where in case removing user, game1 deleted , user removed game2 result is
game | host | clients game2 | userb |
ps2 : beans ejb3.0. methods called delegate class. beans in delegate class instantiated using initialcontext.lookup() method. note logging in ,creating , joining games appropriate delegate class calls correspondent ejb transactions. in case of logout, delegate calls ejb logout user becuase other stuff must done (as said above) ejb calls other ejb (again using lookup() ) has methods removegame(), removeuserfromgame() etc. after methods executed user logged out. maybe has fact the first entity manager called delegate second inside ejb , thats why 1 entitymanger can see non-existent user while other cannot? methods have transactiontype.required
thank in advance
i suppose the user object detached , out of sync database. taken cache. not using extended persistence context within stateful session bean. entity managed within transaction entity manager. try search user pk id.
- Get link
- X
- Other Apps
Comments
Post a Comment