Let's suppose my user interface requirements make JSF a good fit for the front-end and business logic complexity, transactional and scalability requirement warrant the use of EJB (session beans and entity). So I write my entities, code business logic in session beans, expose some APIs in session beans to JSF etc.
Now suppose that in certain cases I find it beneficial and much easier in my JSF Web module to work with the entities directly (i.e. for certain queries) and not go through EJB session beans any time time I want to access the database. Is that an acceptable, good architectural solution? Or should the web module use entities only if the whole app is enclosed in the web module without any session beans?
On another note, all JSF tutorials I've come across use entities directly without a separate EJB application module. Can anyone refer me to an example whereby JSF talks to EJB session beans? I'm assuming you'd still have the JSF controllers which would talk to EJB session beans rather than local JPA controllers, right?
Using entities in the JSF managed bean can be done as entities are similar to Transfer Objects (TO) once they are detached form teh EntityManager persistent context. So it wont harm at any cost.
But one pinching thing about your query is using the entity manager in the JSF managed bean itself to persist or update the entities from the managed bean itself. Which is a wrong sign as Manged beans are not
1) Thread safe
2) Cant manage transactions
3) Not as secured as EJB
soooo it would be bad approach to use the entity manager to persist the entites or act on entities in the managed bean itself.
Thanks & Regards,<br />Shivaji Byrapaneni.
Joined: May 06, 2009
Shivaji Byrapaneni wrote:Using entities in the JSF managed bean can be done as entities are similar to Transfer Objects (TO) once they are detached form teh EntityManager persistent context. So it wont harm at any cost.
Perhaps I didn't make it clear but I meant to use JSF managed beans only to access the database for read-only purposes. From what you're saying it should be ok. However, I would imagine I'd still need Entity Manager to access the data. Why would I want to do without Entity Manager?