Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

which framework is being used most in Persistence Layer?  RSS feed

 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I've come across some frameworks, technologies that can be used in Persistence layer.
like
  • Hibernate
  • Spring's HibernateTemplate
  • Spring's JdbcTemplate
  • Spring-data JPA

  • I want to know which is most preferred API/technology that is being used in Persistence Layer in java based web projects nowadays?

    thanks in advance
     
    Arun Singh Raaj
    Ranch Hand
    Posts: 176
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    want to add JpaTemplate to the list as well.
     
    Ranch Hand
    Posts: 36
    Java Mac OS X Spring
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Most preferred would be Spring Data-JPA as it is the most recent out of the ones mentioned ones above.
    That being said, it prevents lot of boilerplate code and supports Query methods which are quite convenient.

    I would like to add something more recent which is not much in picture currently but it should be in near future.

    Going reactive with Spring Data

    -Ankur






     
    Bartender
    Posts: 1867
    81
    Android Chrome IntelliJ IDE Java MySQL Database
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Spring Data is included with Spring 5 (released Sept 2017) and Spring Boot 2 (currently at RC1).
    Pivotal (creators/maintainers of Spring) have a certification exam for Spring 5.
    I'd expect Spring Data to become more common place as people start using Spring 5 and/or Spring Boot 2.
     
    Arun Singh Raaj
    Ranch Hand
    Posts: 176
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for your response, Ankur and Pete.
     
    Bartender
    Posts: 19996
    95
    Android Eclipse IDE Linux
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Spring Data has been around a long time now. I used Spring Data's JDBC template when I first adopted Spring because I liked its ability to deal with the dreary repetitive and error-prone tasks of setting up, using, and releasing JDBC Connections. Shortly thereafter I moved to Spring JPA on a project that was probably done 10 years ago now. I've also used the Spring Data Neo4J facility for a project that was relation-oriented.

    Spring - unless it has changed for the worse - is modular. Meaning that the core of Spring was fairly small, but you could add Spring Module jars to your project for whatever functions you needed. For example, spring-orm for JPA support.

     
    Arun Singh Raaj
    Ranch Hand
    Posts: 176
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for the information, Tim.
    Had you used Spring data Jpa in your project 10 years ago?
    Then may I know which technology or framework is being used most under Data Layer nowadays?
     
    Tim Holloway
    Bartender
    Posts: 19996
    95
    Android Eclipse IDE Linux
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I would use pretty much the same setup now as I did then. JPA is part of the JEE standard, Spring supports it, and both are pretty much the same as they were back then, allowing for improvements.

    The biggest difference would be in whether or not I'd use an SQL database. As I said, I've already used Spring with Neo4J, and then there are things like MongoDB and its friends. Whatever fits the needs and environment best...
     
    Arun Singh Raaj
    Ranch Hand
    Posts: 176
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hello Tim,
    may I know how do you handle Exceptions in Data Layer in Spring data jpa. As some db operational methods we have to write explicitly in repository class as per our requirement, do you write try-catch block within the methods or any other way you do have to handle the exceptions occurred in DAO methods?

    Thanks.
     
    Arun Singh Raaj
    Ranch Hand
    Posts: 176
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I want to add a question, can @ControllerAdvice handles the exception occurred in Data Layer?
     
    Tim Holloway
    Bartender
    Posts: 19996
    95
    Android Eclipse IDE Linux
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I do a 2-layer persistence scheme.

    The top layer is business-related. It deals with high-level constraint checking and working with sets of associated records. For example, I have an app that maintains a system of bus routes and schedules. So a schedule is often associated with a route, which contains a set of bus stops. There are generally multiple schedules for each route, since most buses repeat the route during the day. I could collect all of the schedule information for a route in a single JPA "working set" if I wanted to display or edit it.

    The next layer is my DAO layer. Unlike the persistence service layer, it doesn't deal with business logic and each DAO works with only one table, or in the case of a tight parent-child relationship, the parent and its children.

    Both layers are transactional at the method level. The DAO layer inherits transactions from the service layer methods. For consistency's sake, some service methods may pass through directly to a DAO if there are no complications, but all higher-level (non-persistence) logic calls only service methods and never calls DAOs directly.

    And finally, the service layer detaches all objects before returning a working set to a higher-level method. This give flexibility and helps preserve database integrity.

    Since Spring is handling all this, exceptions that are thrown are intercepted by the Spring Data methods, which handle commit/rollback, and converted to normalized exception types, since SQL exceptions are a really ragged bunch. If a DAO or service method needs to bounce stuff along with context, I may construct an unchecked Exception and include the original Exception for low-level context and debugging. I don't usually throw JPA or Spring exceptions out of the service persistence layer. Instead, I either return a fault indicator or I convert the database exception to a custom business exception and throw that.

    This gives me a well-organized, flexible, and reliable persistence infrastructure, whether it's in a webapp or in some other form of application.

    I don't recognize @ControllerAdvice, but I'm thinking it's part of the Spring Web framework, which I don't use, as I prefer JavaServer Faces for the most part. As you might imagine from the description I gave above, I don't include web-related functionality in my persistence layers, so that would include not using @ControllerAdvice there. JSF doesn't employ user-defined Controllers, anyway, but I wouldn't put them in the persistence layer even if it did.

    Incidentally, while I said that I don't allow persistence exceptions to exit the persistence layer, there is one, er, exception. That's ValidationException. Although in many cases, validation is done by the service layer, some of the really low-level stuff, as well as actual database schema constraints, may get thrown all the way up. When properly set up, the JavaServer Faces framework will convert them to JSF validation exceptions. Actually, I think that's done by the JSF validator looking for the annotations on the object model and invoking field-level validation without actual database logic, but in any event, that allows me to have a single point of validation for objects which used as both ORM Models and web GUI Models. An advantage of using POJOs as data models.
     
    Saloon Keeper
    Posts: 5052
    135
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It's hard to say what is most used nowadays, but JPA is a good bet. So any JPA implementation (like Hibernate) seems future-proof.
     
    Arun Singh Raaj
    Ranch Hand
    Posts: 176
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for the detailed information.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!