I would like to ask expert opinion regarding the correct use of entities, service and views. It's regarding best practices, so I hope my question doesn't get flagged as too vague.
So I have the following components in my app (only regarding the session):
//database table that holds current session info
@Entity
@Table(name="oauth2_customer_session")
public class OAuth2CustomerSession implements Serializable {
//get/set properties
...
}
//the service that retrieves and updates OAuth2CustomerSession entity
@Stateless
public class SessionService {
@PersistenceContext(unitName = "acme-db")
private EntityManager entityManager;
...
}
//the backing bean
@Named("customerSession")
@SessionScoped
public class CustomerSessionBean implements Serializable {
@EJB
private SessionService sessionService;
private OAuth2CustomerSession customerSession = null;
private HttpSession session;
public CustomerSessionBean() {
session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
}
@PostConstruct
private void init() {
sessionId = session.getId();
//service will return a valid customerSession object
customerSession = sessionService.findCustomerSession(sessionId);
}
...
}
Right now, I'm passing the customerSession object as a parameter in a few of the sessionService methods.
I'm thinking this way, the sessionService remains stateless, thus reducing overhead? But would passing the customerSession object create too much overhead and/or violate the recommended guidelines?
thanks in advance!