cancel
Showing results for 
Search instead for 
Did you mean: 

EJB and Session beans - Which to use when?

ashish_shah
Contributor
0 Kudos

Hi Experts,

I want to access a oracle database using jdbc connectors.

I want to fire a select query using the EJBs.

Can you help me in deciding how do i access these oracle tables .. using which bean?

Entity bean or session bean?

can anybody give me some examples on this?

Thanks in advance.

Regards,

Ashish Shah

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Ashish

One stateless bean with four methods is better.

Regards

Pratyush

Former Member
0 Kudos
Former Member
0 Kudos

Hi ashish

Basically entity beans model business concepts that can be expressed as nouns. For example, an entity bean might represent a customer, a piece of equipment, an item in inventory. Thus entity beans model real-world objects. These objects are usually persistent records in some kind of database.

Session beans are for managing processes or tasks. A session bean is mainly for coordinating particular kinds of activities. That is, session beans are plain remote objects meant for abstracting business logic. The activity that a session bean represents is fundamentally transient. A session bean does not represent anything in a database, but it can access the database.

Thus an entity bean has persistent state whereas a session bean models interactions but does not have persistent state.

Session beans are transaction-aware. In a distributed component environment, managing transactions across several components mandates distributed transaction processing. The EJB architecture allows the container to manage transactions declaratively. This mechanism lets a bean developer to specify transactions across bean methods. Session beans are client-specific. That is, session bean instances on the server side are specific to the client that created them on the client side. This eliminates the need for the developer to deal with multiple threading and concurrency.

Unlike session beans, entity beans have a client-independent identity. This is because an entity bean encapsulates persistent data. The EJB architecture lets a developer to register a primary key class to encapsulate the minimal set of attributes required to represent the identity of an entity bean. Clients can use these primary key objects to accomplish the database operations, such as create, locate, or delete entity beans. Since entity beans represent persistent state, entity beans can be shared across different clients. Similar to session beans, entity beans are also transactional, except for the fact that bean instances are not allowed to programmatically control transactions.

Hope it helps

Regards

Pratyush

ashish_shah
Contributor
0 Kudos

Hi Pratyush,

Thanks for providing the basic knowledge of Entity bean and session beans.

Can you please help me with some example / tutorial on how to access(fire a select query) some database using Entity bean or session beans?

Regards,

Ashish Shah

Former Member
0 Kudos

Hi Ashish,

U can find the examples & tutorials here

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/49f2ea90-0201-0010-ce8e-de18b94aee2d#20">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/49f2ea90-0201-0010-ce8e-de18b94aee2d#20</a>

u can check this Using EJBs in Web Dynpro in Backend Access/ Model section.

regards

Sumit

ashish_shah
Contributor
0 Kudos

Hi Sumit,

Thanks for the link.

This tutorial focuses more on how to access the EJB from WebDynpo.

I want a tutorial or example on how to develop Session beans or entity beans to access oracle DB through JDBC connectors.

Regards,

Ashish Shah

Former Member
0 Kudos
Former Member
0 Kudos

Hi ,

Check the following link

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b00917dc-ead4-2910-3ebb-b0a63e49ef10">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b00917dc-ead4-2910-3ebb-b0a63e49ef10</a>

Regards,

Abdullah

ashish_shah
Contributor
0 Kudos

Hi,

Consider this scenario : I have to access four different database tables for four different purpose.

How should i access the database,

1) Should i create 4 different stateless session beans and write the methods in each of this Session beans.

2) Should i create 1 Stateless session beans and add 4 methods in this one stateless session bean?

Regards,

Ashish Shah

Former Member
0 Kudos

you need to refer some design patterns:

http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html

Message was edited by:

Armin Reichert