Performance, Best Practice
solsticepan.pneuburger.neuburger-edv.de Aug 13, 2009 9:32 AMHi,
i have a (simple) question about Performance and Best Practice with Seam.
is this example Code a good Programming Style (and also with EJB)
Example Code:
A Session Bean generated from Seam, a little modified..
@Name("userHome")
@Scope(ScopeType.SESSION)
public class UserHome extends EntityHome<User> {
@Override
public void create() {
super.create();
}
@Override
@Factory("userH")
public User getInstance() {
return super.getInstance();
}
@Override
public String persist() {
return super.persist();
}
}
Then I have another Bean, a Stateless ONE
@Name("userActionBean")
@Scope(ScopeType.STATELESS) //STATLESS
public class LinkActionBean {
@In
private EntityManager entityManager ;
@In(required = false)
private UserHome userHome ;
/** Generated from Seam, extends the EntityQuery Interface
@In(required = false )
private UserList userList ;
//now i have my business Operations
public String saveUser() {
//get the values from presentation view
User user = createNewUserFactory() ;
user.setPassword(getInstance().getPassword() ) ;
user.setUsername(getInstance().getUsername() ) ;
//and so on....
entityManager .persist(user) ;
return "persist"; //this one is for navigation, if persist then redirect to another view
}
//get the instance from user, when he changed his Address and so on
public User getInstance() {
return userHome.getInstance() ;
}
//create a new user if Admin creates one
public User createNewUserFactory() {
return new User() ;
}
My Question: Is it correct to call a Session Bean from a Stateless Bean (or Scope) for some Business Operations ?? Performance, Best Practice and so on...??
If not can you explain me why should may I avoid this ?
I read the Book Seam Manning in Action, but the Examples in this Book don´t answer this Question, or I missed that.
Thanks Peter