Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8747115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:18:15+00:00 2026-06-13T12:18:15+00:00

i examine lots of samples but i didn’t find an adequate solution for this.

  • 0

i examine lots of samples but i didn’t find an adequate solution for this.
Some documents say “Ideally your business logic layer shouldn’t know there is a database. It shouldn’t know about connection strings or SQL.”

I found some samples which locate the business logic to @Service annotated classes but they use SQL/HQL in @Service methods.

What should be the ideal usage? If we want to change database or persistence technology should we change only @Repository annotated classes or both of them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:18:16+00:00Added an answer on June 13, 2026 at 12:18 pm

    I prefer putting all persistence-related stuff (i.e. queries, and everything dealing with JDBC, JPA or Hibernate) in a DAO layer, and have the service layer rely on this DAO layer for persistence-related stuff.

    But the main goal is not to be able to change the persistence technology without affecting the service layer. Although that could be possible if you switch from Hibernate to JPA, for example, it wouldn’t be if you switch from JPA to JDBC, for example. The reasons are that

    • JPA automatically persists all the changes made to entities without any need for update database queries , whereas JDBC doesn’t, and thus needs additional update queries
    • JPA lazy-loads association between entities, whereas JDBC doesn’t
    • …

    So changing the persistence technology will affect the service layer, even if all the persistence stuff is isolated in DAOs.

    The main advantages of this decoupling, IMHO are

    • clearer responsibilities for each class. It avois mixing persistence-related code with business logic code.
    • testability: you can easily test your service layer by mocking the DAO layer. You can easily test the DAO layer because all it does is executing queries over the database.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Examine this example. It is in PHP, but you should be able to pick
Examine the following code: This works: T *p = (std::find( this->first(), this->last(), *pPos ));
I am trying to examine the contents of an assembly and find all classes
I sometimes check out some previous version of the code to examine or test.
Examine the following snippet: assertThat( Arrays.asList(1x, 2x, 3x, 4z), not(hasItem(not(endsWith(x)))) ); This asserts that
I examine the parameters of a C# method using reflection. The method has some
Let's examine this line of codes (only 1 actually change anything) PO(self.containerForFormerHeader); PO(self.containerForFormerHeader.subviews); [self.containerForFormerHeader
Examine this code var _class=function() { this.Test=100; this.Callback=function(msg) { alert(msg+\r\n+this.Test); } } function run(call)
I wrote this code to examine behaviour of destructors in c++ #include <vector> #include
I want to examine what SQL statements are generated by Ebean to find out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.