• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How design the service classes?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've started on a simple Spring Diary application that uses JPA and Hibernate for ORM.
I have a couple of models that depend on each other. For instance a User can have many Days which can have many Notes. So I created a service-class for each model. But when I want to create a Day I need access to the corresponding User object that must be set. I don't want to have multiple service classes injected in one controller. That feels bad somehow. Is it bad?

My question is basically: What is the best approach when designing service classes for Spring? Should I just put it all in one service class and persist or merge the User when I want to save my changes? That feels so wrong! I want every class to do one thing for ease of maintainability. One big bloated service class is harder to understand and maintain is my opinion. Should I have service classes that call other service classes? Should I start with the models or the use cases or is there some other approach?

I'm surprised that I can't find any examples on how to design this crucial part of the application.
 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why you are using Hibernate and JPA both for Persistance ?
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should have only UserRespository. User is an aggregate root.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kri shan wrote:Why you are using Hibernate and JPA both for Persistance ?


JPA is specification/set of interfaces, Hibernate EntityManager is an implementation of JPA.
 
Daniel Näslund
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kengkaj Sathianpantarit wrote:You should have only UserRespository. User is an aggregate root.



Thank you for your quick feedback! That makes sense when I think about it. I'll go with a UserRepository.

 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Näslund wrote:

Kengkaj Sathianpantarit wrote:You should have only UserRespository. User is an aggregate root.



Thank you for your quick feedback! That makes sense when I think about it. I'll go with a UserRepository.


That's okay. Whenever you have time, I recommend to read Domain-Driven Design book.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kengkaj Sathianpantarit wrote:

Daniel Näslund wrote:

Kengkaj Sathianpantarit wrote:You should have only UserRespository. User is an aggregate root.



Thank you for your quick feedback! That makes sense when I think about it. I'll go with a UserRepository.


That's okay. Whenever you have time, I recommend to read Domain-Driven Design book.



A great book, and a great recommendation.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic