This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
We are to design a Persistence layer as part of the development process. I would like to know which combination from the below that would be ideal for the requirement as stated below,
Technology combinations :
(1) Spring + Hibernate
(2) Spring + JPA
(1) Application should be easily portable across different app servers
(2) Application should be scalable
(3) Application should easily integrate with any new orm tool that might be used in the future
What is your suggestion guys?
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Now if I have a Persistence layer that has thee different technologies to access the database (like Hibernate, JDBC, iBatis) could I build a wrapper around this by using Spring that controls all three technologes for databse access? For example, can I do something like this,
If the above would be possible, then how would I control my transactions?
As for the second question, it is possible, you can use a mix of technologies in your persistence layer. To control transactions, mark classes or methods in your service layer with the '@Transactional' annotation and add '<tx:annotation-driven>' to your spring application context configuration. Spring will start a transaction at the beginning of the method call, the transaction will be live as the service layer class makes calls to your persistence layer, and the transaction will end when the method in the service layer class ends. For more information check out the chapter on transaction management in the Spring documentation.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Thanks Nathan! The transaction would be managed by the EJB Session bean which forms the service layer of my application. Would this fit in the kind of Persistence layer that I'm trying to build? I mean the transaction propogation and so on...
I checked out the docs from Spring and of course some browsing and found that I can user Spring + JPA (with HibernateJpaVendorAdapter) as the JpaVendorAdapter.
Now the Question that pops up my mind is that what would be the difference when I wire a LocalSessionFactoryBean or a LocalContainerEntityManagerFactoryBean to my Persistence layer. What is the difference between the two and of course with the latter (LocalContainerEntityManagerFactoryBean), I'm using Hibernate as my JPA implementation. Where is the difference? I know that JPA is a standard but apart from that what is the major advantage of the latter approach (with LocalContainerEntityManagerFactoryBean)?
LocalContainerEntityManagerFactoryBean is used with JPA and LocalSessionFactoryBean is used if you're using Hibernate directly. The main advantage (in addition to JPA being a standard) is that JPA requires less configuration - it's mostly just annotations on your beans.