Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Persistance Application Stateless vs. Stateful

I am new in JPA and I can't understand the use and the difference between stateless and stateful.

Any experiences?

regards, Haythem

like image 471
Haythem Avatar asked Dec 13 '22 16:12

Haythem


2 Answers

Stateless and Stateful are EJB Session Bean concept, not of JPA.

Nota bene: JPA is part of EJB specification, but can be used separately and outside of an EJB container. This is what usually causes the confusion.

Edited: A useful SO thread, Why Use Stateful Session Beans.

like image 78
Adeel Ansari Avatar answered Jan 15 '23 05:01

Adeel Ansari


"Stateful" and "Stateless" are attributes for session beans.

A session bean (in brief) provides a way to call methods on an application server. The bean is an instance of a java class. Usually, a bean is destroyed after the remote method terminates (and returns a result). Those bean are "stateless".

It is possible (but rather unusual) to add fields and attributes to the bean so that a client can "create" this instance on the server and use it for more then one operation. Those beans are "stateful" (and should be avoided).

like image 37
Andreas Dolk Avatar answered Jan 15 '23 06:01

Andreas Dolk