2

I recently started reading a book that explains in more detail the manipulation of databases, in terms of the relationships between them, especially. The problem is that this book is a bit old, from 2014. So I come with the following questions, to which you can clarify, please:

In the book we use Dao, Dto and Service pattern, but we can't use JPA, Spring Boot Repository or other new technologies to "replace" the old implementation that the book presents?

If so, can you give me an alternative to the code below, and how does it work? What could I improve, what could I give up, what should be completed, what should I learn, please!

Book divide the implementations of an Application in 2 teams:

  • UserInterface (Data Transfer Object of the entity, singleton in Memory DB and Controller as Mock Service and view)

  • Development Team (with creating the Entity and testing using TDD, creating DAO for that Entity, Business Service Tier and Presentation Tier

So, I can change this way of creating and manipulating the applications and Databases, if yes, how, and why? What should I use, how should I do it?

This is the git of the book I'm currently reading: https://github.com/Spring-Hibernate-Book/spring-hibernate-datamodeling-tdd-rest/tree/master/Spring-OODD/src

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
MyProblems
  • 69
  • 1
  • 10

1 Answers1

2

As far as division of labor, the concept of having a separate team work on the controller layer seems antiquated. It could be that the single-page-UI has its own team, but many places prefer that the same people work on everything for a feature front to back, in order to reduce opportunities for communication problems between teams.

The extent to which you need DTOs should be up to the developer's discretion. It used to be a practice to routinely copy all entities into DTOs to avoid issues like lazy-loading in the UI. If you are building a single-page application where you're passing JSON to the UI that isn't an issue. The single-page application architecture provides better separation between UI concerns, making DTOs less necessary in most cases.

For the rest of this the concepts should map over. A Spring JPA repository has the same function as a data access object, it just provides more of the implementation for you. The biggest change associated with the Hibernate mappings is to use JPA annotations instead. Services haven’t changed.

TLDR

things that have changed:

  • single-page applications have replaced serverside approaches like JSPs
  • standardizing on JPA instead of Hibernate
  • configuration classes, no application context XML anymore
  • profiles
  • focus on microservices vs. monoliths
  • more batteries-included (h2 by default, deployable jars, convention over config)

things that haven't changed:

  • general layering scheme of controllers calling services calling data access
  • Hibernate mapping strategies and general ORM issues
  • Spring transaction support
  • general Spring programming model with beans, DI, AOP
Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • So the book is outdated, thank you for clarifying that. I think the relationships it presents between entities are still in use, so it's good to know how it works, even if the implementation has changed, no? Can you recommend me a book or something presents what this book presesents, please? Another thing I'm confused about is using the annotations: Service, Repository. I think we'll use it as a repository for Jpa Repository, but for now, what is Service for? In the respective book we use Service, with the annotation, but being outdated, can we change something in this approach? – MyProblems Dec 05 '20 at 14:20
  • @MyProblems: for what services should do, you might try reading https://stackoverflow.com/q/3688664/217324 or https://stackoverflow.com/q/3885675/217324. use of annotations for spring components hasn't changed, configuration has gotten a lot easier. – Nathan Hughes Dec 05 '20 at 14:24
  • thanks for the link and for the answer. If we use Spring Boot Repository annotation, we can use it instead of using DAO classes? If yes, is okay of doing this? I mean it's a lot easier doing this way. I saw and understood the using of Service annotation, thanks. Do you have an idea where i can find projects or things like that book from where i can learn more? – MyProblems Dec 05 '20 at 14:58
  • there are a bunch of tutorials for spring-boot. depending on what you want this book may still not be bad, just understand it is likely assuming more of an old school approach to building monoliths, where spring is trying to be oriented toward microservices. – Nathan Hughes Dec 05 '20 at 17:29