What is a persistence?


Meaning of the persistence is one of the most imporant thing in application development. Nowdays almost all applications require persistent data so it is very important for an system to preserve data entered by users even if the machine was powered off. Persistance in Java ( Hibernate ) is storing data in a relational databse using SQL.


Relational technology provides a way of sharing data among different aplications or among technologies that form part of the same application. Relational technology is a common denominator of many different technology platforms and systems so it is't specific to a particular application.

Persistent classes


Not only does Hibernate enable a programmer to gain an independence from a given database but it can also manage a state of persistent objects. A programmer may not be aware when and which queries are performed to a database.

Objects of classes mapped by Hibernate may appear in three states:

Transient - we create objects in this state by means of new. This kind of object is not connected with any session of Hibernate. It is a normal Java object and can be changed into Persistent state.

Persistent - these kinds of objects are connected with both: data in a database and a given object of Session class. Hibernate detects changes in them and put them to a database at the end of a session.

Detached - an object is in this state if it used to be Persistent but an appropriate session was closed. Later, it may be connected with other session. Creating, saving and loading objects.

Almost each Java class may be mapped by Hibernate.
It cannot be finished - it is because of the architecture which overloads persistent classes.
It should have an identifier - Hibernate uses it to test equality.
It must have a default constructor.
Mapped fields must be public or have appropriate get/set methods.
It is a common practice to use classes with JavaBean pattern (i.e. those having appropriate get/set methods for given fields) as persistent classes.