aspose file tools*
The moose likes Other Application Frameworks and the fly likes Technology related question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Technology related question" Watch "Technology related question" New topic
Author

Technology related question

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Guys,

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

Requirements:
(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!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Guys,

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?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

Any suggestions guys!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

JPA is a standard, Hibernate is an ORM (that includes an implementation of that standard). So if you want ot follow the usual advice, code to the standard.

Other than that this is a Spring question so I'll move it to a more appropriate forum.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

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...
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

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)?

Ideas really appreciated!
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.

As for using a EJB Session bean as the service layer - I haven't done this before, but I found a IBM DeveloperWorks tutorial/article about it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Technology related question