Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF and session beans  RSS feed

 
Tomasz Romanowski
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Shivaji Byrapaneni
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
4) etc..

soooo it would be bad approach to use the entity manager to persist the entites or act on entities in the managed bean itself.
 
Tomasz Romanowski
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!