This content has been marked as final.
Show 1 reply
-
1. Re: calling entity finder method from session bean
semi Mar 20, 2004 9:04 PM (in response to chaloupka)Is the following code a call to the finder method on the home-interface of the LocalSells-Bean?
Collection users = lh.findUsersToValidate();
If so then the result is a collection of SellsLocal-Objects.
Your finder method returns a collection of pk objects (collection of String-Objects in your case)
But the result of a call to the finder method is a collection of LocalSells-Objects.
You don't need to invoke the findByPrimaryKey method for each of them. This is done by the container.
I don't understand your code at all. Is SellsBean validating users (UserBean) or vice versa?
They seem to use the same PK. ResultBean is using UserPK too?... LocalSells sells = lh.findByPrimaryKey(user); ResultBean bean = sells.validateUsersSells(new UserPK(user)); ...
If the value of 'user' is the primary key of LocalSells then LocalSells knows it and you don't need to pass the PK to it.
I would say, you are searching for users whos sells are not validated and want to validate them and return a result to the client. Aren't you?
This is allways the same question. Should a 'parent'-entity know about it's children or not. In your case, should UserBen know SellsBean?
I would prefer the following code:public Collection validateAllSells() { UserHome userHome = .....; Collection userList = userHome.findAllBySellsState(4); ArrayList validationResult = new ArrayList(userList.size()); Iterator userIterator = userList.iterator(); while(userIterator.hasNext()) { ... validationResult.add( validateUserSells((UserLocal)userIterator.next()) ); ... } return validationResult; } private ValidationResult validateUserSells(UserLocal user) { SellsHome sellsHome = .... Collection usersSells = sellsHome.findAllByUserAndState(user.getID(), 4); ValidationResult validationResult = new ValidationResult(user.getID()); Iterator sellsIterator = usersSells.iterator(); while(sellsIterator.hasNext()) { SellsLocal sells = (SellsLocal)sellsIterator.next(); ... // do some validation and store the result in 'validationResult' } return validationResult; }
The only dependency of UserBean on SellsBean is the finder method findAllBySellsState(int state)
An other solution were iterating trough UserSells directly without to use UserBean at all (something like SellsHome.findAllByState(4)).
Michael