• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

session bean versus entity bean

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its a battle between seeion beans and entity beans
Can any one tell me that why do i use an entity bean if i can provide persitence in my session bean itself

and also which is better cmp or bmp

thanks to all in advance
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Its a battle between seeion beans and entity beans
Can any one tell me that why do i use an entity bean if i can provide persitence in my session bean itself



Hi,

This has been discussed a lot of times in this forum, so a search will help. Entity lifecycle is different than the session beans and theyrepresent persistent objects, it has methods like ejbStore, ejbLoad etc which can be used to update and retrieve the values from the database. Entity beans represent shared data unlike session beans.

If you make use of CMP you will not have to write any sql Queries. CMP is better than BMP in most of the cases (ever since EJB 2.0 has come into existence)but in cases of legacy systems you will left with no choice but to use BMP.
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Its a battle between seeion beans and entity beans
Can any one tell me that why do i use an entity bean if i can provide persitence in my session bean itself


I think the 2 beans focus on different areas.

Session bean focuses on workflow, i.e., when a request comes in, if it contains several operations, the session bean will cater for these operations, call the local components to carry out the task, or request for remote components if they are not locate in the local machine.

Entity bean focuses on entity, it is a representation of data object inside data source. Thus, whenever you got an entity bean, you are accessing the data object, not the workflow.

Thus, if you mix up the 2 things, you simply mix up the workflow and the data objects. Just like you dont wanna use MVC model, while you put everything inside 1 single JSP/Servlet (access flow, data retrieval and data presentation).

They are not fighting to each other, they are supplementing each other.


and also which is better cmp or bmp


In old days (EJB 1.0 and 1.1), BMP is better becos at that time, the containers are too weak. Lots of problems discovered in their services.

Nowadays, as the containers become more and more powerful, people tends to use CMP becos this saves lots of programming effort, and the codes become reusable.

Keep in mind that, we wanna reuse those business components. If we hardcode some application dependent logic (like when the transaction commits) into the objects, it may or difficult to be reuse becos another application may not commit the transaction at the same function/point.

However, if we use CMP, for different transaction attributes, AA can simply configure the attribute with different values, so that the codes are not needed to be changed.

Nick
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you implement functionality that has to be shared across a wide range of clients you will use a SessionBean that runs in a EJB container (not entirely unlike a COM object on a MTS!). The container will take care of nasty things like transaction handling, caching and pooling. That's about all there is with EJB's, you can build perfectly sound (enterprise) applications by using SessionBeans only. In fact a lot of vendors did not implement EntityBeans with their EJB 1.0 container.

EntityBeans offer you a framework for persisting your datamodel. You will not have to code your data layer (in theory and as long you're using a SQL database to persist) yourself, which is called CMP (and CMR). When your data is not on a SQL database you will have to use BMP. But the only good reason to use BMP I can think of, is re-using the EntityBean interface and thereby making it remote.

With that reason, I do not see much sense in giving an EntityBean a remote interface. Instead I will advise to use EntityBeans with local interfaces (advance: better handling of CMR), which can be operated on by SessionBeans (design pattern: SessionFacade).

My point: SessionBeans are the important thing. EntityBeans (especially as of EJB2.0 and in combination with a SQL database) can be handy in persisting your datamodel and at the same time reduce your LOC (which I consider a good thing).

Edward Peters, SCEA

PS I consider your question Can any one tell me that why do i use an entity bean if i can provide persitence in my session bean itself a very good one.
[ July 21, 2004: Message edited by: Edward Peters ]
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Its a battle between seeion beans and entity beans
Can any one tell me that why do i use an entity bean if i can provide persitence in my session bean itself




When to use SEssion Bean

In general, you should use a session bean if the following circumstances hold:

At any given time, only one client has access to the bean instance.
The state of the bean is not persistent, existing only for a short period (perhaps a few hours).
The bean implements a Web service.
Stateful session beans are appropriate if any of the following conditions are true:

The bean's state represents the interaction between the bean and a specific client.
The bean needs to hold information about the client across method invocations.
The bean mediates between the client and the other components of the application, presenting a simplified view to the client.
Behind the scenes, the bean manages the work flow of several enterprise beans. For an example, see the AccountControllerBean session bean in Chapter 36.
To improve performance, you might choose a stateless session bean if it has any of these traits:

The bean's state has no data for a specific client.
In a single method invocation, the bean performs a generic task for all clients. For example, you might use a stateless session bean to send an email that confirms an online order.
The bean fetches from a database a set of read-only data that is often used by clients. Such a bean, for example, could retrieve the table rows that represent the products that are on sale this month.




When to use Entity Bean

You should probably use an entity bean under the following conditions:

The bean represents a business entity and not a procedure. For example, CreditCardBean would be an entity bean, but CreditCardVerifierBean would be a session bean.
The bean's state must be persistent. If the bean instance terminates or if the Application Server is shut down, the bean's state still exists in persistent storage (a database).

 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Discussion in CMP VS BMP

http://www.theserverside.com/discussions/thread.tss?thread_id=1755

AND



Why choose a CMP Architecture ??
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic