..
Spring framework supports integration with many for 'ORM (object relational mapping), but for reasons of exposition, we focus only see how to integrate Hibernate and JPA in a Spring project.
Spring framework supports these operations such as management of resources, implemantazione DAO (Data Access Object) and transaction management.
Through the integration with Spring you can configure these frameworks through the use of DI (Dipendency Injection).
The itegrazione with Spring also gives you a host of benefits like:
Spring makes it easy to change the configuration required by the framework and implementations for testing in isolation.
Spring can translate specific exceptions in DataAccessException ORM framework so that these exceptions can be handled in the business layers of abstracting from the specific API used.
To do this, Spring has its own hierarchy of DAO Exception that is applicable to any data access strategy.
For example, if on using JDBC directly, all are translated into SQLException DataAccessException, also including the translation of the SQL error codes.
If you use an ORM like Hibernate or JDO you have to do with HibernatException PersistenceException or that can be translated into IllegalArgumentException or IllegaleStateException, so abstracted from the specific implementation of the layer.
To enable the translation of exceptions just use the '@ Repository annotation and configure the PersistenceExceptionTranslationPostProcessor:
@ Repository
MyDaoImpl {public class implements MYDA
//................
}
and nell'applicationContext. xml:
<! - Translation of exceptions -> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> <bean id="myDao" class="example.MyDaoImpl"/>
the Spring application context can easily recover all the resources necessary to create your ORM, such as the DataSource or the configuration of Hibernate SessionFactory, centralizing, in fact, these resources and making it easier to change them.
It also offers other advantages, such as the sharing of the session in a completely transparent.
Spring can manage transactions automatically or manually.
Whichever way you choose, the central point of management transactions is the use of AOP.
By choosing to be done automatically using the @ Transactional annotation, if you prefer a manual need advice in its reporting to the Application context configuration file.
This makes centralized management, as always, easy to move from a transaction manager to another, like going from local transactions to JTA.
The transaction management will be discussed in detail in the following paragraphs.
The purpose of the Spring ORM is to create a Data Access application layer in order to be released, on the one hand, the layer of business logic from dipendeze related to data access and transaction processing and other developer so to eliminate the singletons and the hard-coded resource lookups.
In the following example we can see an ORM layer that uses Hibernate for data access and JTA for transaction management:

| |
Linux (Course)
Complete guide to open-source system. From 49 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |
| |
Ruby and Ruby on Rails (Course)
Create software and Web applications with Ruby and RoR. From 39 €. |