aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes �Session Beans vs Entity Beans� Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "�Session Beans vs Entity Beans�" Watch "�Session Beans vs Entity Beans�" New topic
Author

�Session Beans vs Entity Beans�

jose maria
Greenhorn

Joined: Jan 29, 2002
Posts: 5
First of all, sorry bout my english.
I am developing a J2EE/EJB Web Application using SessionFacade pattern.
The problem is that most of developers advice me not to use Entity Beans if I have lots of users, so I decided to use Session Stateless Beans.
if so...
Which are the advantages of using EJB instead of usual java Beans w/ JDBC Api??? Because I lost the (I think) main advantage what is transaction management...
Does session facade pattern makes sense then?
Where must I make DB calls? in session beans or must I develop some clases for the DB access to be called from SessionBeans?
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
First of all, sorry bout my english.

Don't worry, mine is not better


The problem is that most of developers advice me not to use Entity Beans if I have lots of users, so I decided to use Session Stateless Beans.

I don't think you could obtain an answer about that.
Some say "Never use Entity beans", other are fans...


Which are the advantages of using EJB instead of usual java Beans w/ JDBC Api??? Because I lost the (I think) main advantage what is transaction management...

1- OO design
2- The EJB container can manage transaction, isolation level, and some security rules for you
3- The container's programmers are supposed to be better than you are. So relying on container is a safer solution.


Does session facade pattern makes sense then?

No, session facades are for Entity beans

Where must I make DB calls? in session beans or must I develop some clases for the DB access to be called from SessionBeans?

You develop classes called DAO (Data Access Object).
EJB calls DAO and DAO contains the code for data access

by the way, take a look at the Naming policy before a sheriff catches you !!
HTH.

[ January 29, 2002: Message edited by: Bill Bailey ]

/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
One thing:

Does session facade pattern makes sense then?
-----------------------
No, session facades are for Entity beans

Sorry, but the Session Facade Pattern works regardless of whether or nor you use Entity Beans. The idea works just as well with plain old Java classes doing the JDBC work as it does with Entity beans.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
jose maria
Greenhorn

Joined: Jan 29, 2002
Posts: 5
Hi, and thanks all for your answers.
Kyle, nice documents!
So, using Facade Pattern I will have:
Client [in my app. a servlet] that ask for data to a Session Stateful EJB [facade].One per use case.
Facade calls Stateless session beans.
And these stateless EJB have DAO for DB calls.
Then the facade returns a serializable object to the servlet that uses it with jsp to generate the view.
Is it right?
So, must I make one DAO per DB query?
Is it better to create the "Java serializable objects" that facade forwards to the servlet inside the DAO itself or return the resultset to the session bean which will create the object.
Thanks again.
[ January 30, 2002: Message edited by: cardiac0 ]
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Well, my preference is to have the DAO make the return objects (the Serializable ones) rather than just returning a ResultSet, but that's personal preference. Your mileage may differ.
When I do so that usually ends up with one DAO per return class type -- which may end up being several related queries.
Kyle
[ January 30, 2002: Message edited by: Kyle Brown ]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
cardiac,
Please note that JavaRanch has a naming standard that you must abide by to post here. You must use your real first name - space - your real last name as your display name.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906

Sorry, but the Session Facade Pattern works regardless of whether or nor you use Entity Beans. The idea works just as well with plain old Java classes doing the JDBC work as it does with Entity beans.


Yes, I know Sun has changed its mind between 2000 and 2001.
In 2000, a facade where ONLY for Entity objects.
Then from 2001, a facade can be for any kind of object.
So you're right Kyle. I was myself too EJB-centric when I answered the question.

for data to a Session Stateful EJB [facade].One per use case.

I don't think you sould have 1 session facade per use case. This will result in too many SF objects.
A better approach should be to "group " related use cases in 1 SF.
For instance createOrder, modifyOrder, deleteOrder could be in 1 SF called manageOrder.
(so the SF aggregate many use cases)
jose maria
Greenhorn

Joined: Jan 29, 2002
Posts: 5
But I still hav one IMPORTANT question...

How can I save the state of every EJB...Now they are not entityEJB, they are Stateless...
How do you save them??? How do you manage this problem...
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
You can have Stateful session beans.
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Originally posted by jose maria:
But I still hav one IMPORTANT question...

How can I save the state of every EJB...Now they are not entityEJB, they are Stateless...
How do you save them??? How do you manage this problem...


Hi,
If you don�t wanna use Stateful session bean as Bill mentioned you�ll have to keep the state on client side and pass it as parameters for your stateless session bean, be aware that this approach should not be used for big ammounts of data(you�ll use the network to pass the state), you may also use http session and keep the client state on the web server.
jose maria
Greenhorn

Joined: Jan 29, 2002
Posts: 5
I still don't understand which are the advantages of using EJB instead of usual java Beans w/ JDBC Api...
If Entity Beans are not desirable and my system does not need distributing objects...why use stateless session beans instead of servlets-javaBeans-jsp???
 
 
subject: �Session Beans vs Entity Beans�