views:

36

answers:

1

HI would like to understand how do ejbs work in an MVC architecture, what i do not get is: When the web app starts, the system creates an ejb for each record in every table of db or an ejb with all the records of all tables?

Thank you very much

A: 

I'm not sure I get the question right, are you speaking of EJB 2 or EJB 3?

In the EJB 2.x model, the so-called Entity Bean corresponded indeed to rows in the database. The beans where created on demand, when the data needed to be accessed. Otherwise that would mean that the whole database gets loaded in memory.

In EJB 3.x, Entity Beans were superseded by the Java Persistence API (JPA). With JPA, you map tables to regular java classes (POJO). Instances of the class correspond to individual rows in the table. No data is loaded at startup. Data is loaded when you query the database through the Persistence API, and then maintained in a cache.

Despite the similarities, and especially the terminology "entity" like in EJB 2 entity and JPA entity, both technologies are radically different. JPA is not an evolution of EJB 2 Entity Bean, it is a replacement.

(EJB 2 entity was an object model in which each entity could be accessed remotely through a unique identity. The approach taken by JPA is a data-oriented model, where you just send data back and forth between the client and the server.)

Hope it helps.

ewernli
Cheers that was exactly what I wanted to know! thank you very much
Ignacio