EJB persistence.

Can anybody help me out to resolve the meaning of persistence related to EJB's. What does persistence mean actually?
[124 byte] By [Dreamersa] at [2007-10-3 6:41:19]
# 1
It means the data persists beyond the life of the program, which usually means it gets stored in a database.
malcolmmca at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 2
Do you mean to say the object persists even after the application server shut down? I am very confused about this. What is the main use of EJB's?
Dreamersa at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 3

> What does persistence

> mean actually?

Most of the times , it means persisting Java objects to a relational database.

Given the "impedance mismatch" between tabular structures in the db and java objects , there are several technologies which aim to facilitate persistence by providing some sort of obj-relational (O/R) mapping. EJB is one of them.

In EJB 2x, Entity Beans were a (poor) solution to the persistence problem.

In EJB 3.0, Entity Beans have become POJOs with annotations, with the O/R mapping largely inspired by Hibernate.

karma-9a at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 4

Your reply was informative but my doubt is:-

The object still persists if there is some database crashes or application server crashes?

I meant suppose if we are using JBOSS and MySql, EJB objects will persist even after Server crash? What is the main use of EJB's?

If possible please explain.

Dreamersa at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 5

> Your reply was informative but my doubt is:-

> The object still persists if there is some database

> crashes or application server crashes?

> I meant suppose if we are using JBOSS and MySql, EJB

> objects will persist even after Server crash?

The EJB will survive if it was persisted prior to the crash.

> What is

> the main use of EJB's?

To ease the development of distributed / "network aware" applications.

kajbja at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 6
You mean to say prior to MySql crash or JBoss application crash? I mean the objects survive if they persist before JBoss crash or Mysql crash?Message was edited by: Dreamers
Dreamersa at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 7

> You mean to say prior to MySql crash or JBoss

> application crash?

Think about it. The EJB can survive if MySQL crashes and JBoss is still running. An EJB can also survive a crash of the application server even if it hasn't been persisted (if the application server is clustered and replicated). The EJB will survive if it was persisted prior to a crash of both the application server and database.

kaj

kajbja at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 8
Ya now I am saying the proper doubt which I had, How can the object survive when there is no Application server running? Will that be stored in some containers so that they can be recoverd later? If so where will that container be?
Dreamersa at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 9

> Ya now I am saying the proper doubt which I had,

> How can the object survive when there is no

> Application server running? Will that be stored in

> some containers so that they can be recoverd later?

> If so where will that container be?

What? The EJB will "resurrected" when the application server is restarted.

Kaj

kajbja at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 10

Think about it. The EJB can survive if MySQL crashes and JBoss is still running. An EJB can also survive a crash of the application server even if it hasn't been persisted (if the application server is clustered and replicated). The EJB will survive if it was persisted prior to a crash of both the application server and database.

kaj

You had replied above saying "An EJB can also survive a crash of the application server even if it hasn't been persisted, An EJB can also survive a crash of the application server even if it hasn't been persisted "

So asked how EJB's can survive after the server crash?

My view was EJB's can only be survived if there is any database crash...

Dreamersa at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 11

> Ya now I am saying the proper doubt which I had,

> How can the object survive when there is no

> Application server running? Will that be stored in

> some containers so that they can be recoverd later?

> If so where will that container be?

Obviously a Java object can't exist outside of a JVM, but the data from that object can be stored to a database or file, and the object reconstructed from that data on subsequent runs.

Persistance managers automate that process so you can ask for an object on the basis of some kind of key or search values and that the object will be built if there isn't one already cached.

Further they keep track of these persistant objects and dump them back to the database when they are found to have changed.

malcolmmca at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 12

Think about it. The EJB can survive if MySQL crashes and JBoss is still running. An EJB can also survive a crash of the application server even if it hasn't been persisted (if the application server is clustered and replicated). The EJB will survive if it was persisted prior to a crash of both the application server and database.

kaj

You had replied above saying "An EJB can also survive a crash of the application server even if it hasn't been persisted, An EJB can also survive a crash of the application server even if it hasn't been persisted "

So asked how EJB's can survive after the server crash?

My view was EJB's can only be survived if there is any database crash...

Email this Topic

Dreamersa at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 13
malcolmmc ,Related to objects thats true but related to EJB how does it work? I mean the basic use of EJB according to me is persistence. So how does object persistence work?
Dreamersa at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 14

> You had replied above saying "An EJB can also survive

> a crash of the application server even if it hasn't

> been persisted, An EJB can also survive a crash of

> the application server even if it hasn't been

> persisted "

> So asked how EJB's can survive after the server

> crash?

It will survive if the state of the EJB has been replicated to a another application server. Some application servers can be configured to work in a cluster which can handle fail over.

Kaj

kajbja at 2007-7-15 1:30:22 > top of Java-index,Java Essentials,Java Programming...
# 15
> Related to objects thats true but related to EJB how> does it work? I mean the basic use of EJB according> to me is persistence. That's wrong. There are different types of EJBs.Kaj
kajbja at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...
# 16
When there is no clustered environment, the EJB's will survive only when database crashes and not application servers. Is it?
Dreamersa at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...
# 17
Yes this was wrong. Session beans are not persistent only entity beans are persistent (CMP and BMP).
Dreamersa at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...
# 18

> Your reply was informative but my doubt is:-

> The object still persists if there is some database

> crashes or application server crashes?

> I meant suppose if we are using JBOSS and MySql, EJB

> objects will persist even after Server crash? What is

> the main use of EJB's?

> If possible please explain.

There are 4 types of EJBs.

1) - 2) Session beans (stateful and stateless) are not meant to survive a server crash, since they're basically in-memory objects.

3) Message-driven beans are removed when the server crashes, but since messages are not lost (QoS), they can be re-delivered when the server restarts and the EJB container gets a bean from the pool again.

4) Entity beans are "views" of the database (an object wrapper around the db data), so it's understandable that they can be "resurrected" after a server crash. When the server is restarted, the container can always find a bean instance to represent persistent data.

Of course, you will lose any data that wasnt committed prior to a crash. This is where you should start looking into clustering .

If your database also crashes, then all the saved changes are also lost unless you have some recovery mechanism to get the data back.

The main (and most successful) use of EJB is not persistence per say, but rather handling business logic in a transactional distributed environment. And that involves mostly stateless session beans.

karma-9a at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...
# 19
Then how persistence is related to EJB's (Iam speaking about Entity beans - CMP and BMP).
Dreamersa at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...
# 20
> Then how persistence is related to EJB's (Iam> speaking about Entity beans - CMP and BMP).What?
kajbja at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...
# 21
I meant how persistence and EJB concepts are related.
Dreamersa at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...
# 22
> I meant how persistence and EJB concepts are related.There isn't a specific relation. Applications usually need to store some data, and that's the relation.Kaj
kajbja at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...
# 23

> I meant how persistence and EJB concepts are related.

They are one model for relatiing Java objects with relational databases. Sure there are non-entity beans, but persistent entity beans are the main point of the excercise.

Instead of doing SQL yourself via JDBC you use an Object-Relational Mapper (ORM). This hides the database activity from the programmer and allows the application programmer (at least) to work entirely with objects, without being concerned how those objects are stored on the database. Ideally you can completely re-think your database design without affecting your application programs (I don't know if anyone ever does this).

malcolmmca at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...
# 24

> Instead of doing SQL yourself via JDBC you use an

> Object-Relational Mapper (ORM). This hides the

> database activity from the programmer and allows the

> application programmer (at least) to work entirely

> with objects, without being concerned how those

> objects are stored on the database. Ideally you can

> completely re-think your database design without

> affecting your application programs (I don't know if

> anyone ever does this).

That is also true for non EJB applications.

kajbja at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...
# 25

> > Ideally you

> can

> > completely re-think your database design without

> > affecting your application programs (I don't know

> if

> > anyone ever does this).

>

> That is also true for non EJB applications.

Sure, if you use another ORM, like Hibernate, for example. Personally I get the impression this stuff is heavilly overused. It could make sense on very large projects where there are complex divisions of labour. For one or two man projects I'm inclined to doubt it's worth doing.

It's the kind of thing that appeals to management rather than technical people. Gives a greater illusion of control.

malcolmmca at 2007-7-21 11:39:04 > top of Java-index,Java Essentials,Java Programming...