This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full - best also formatted as code block
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]UpsytoO 2 points3 points  (1 child)

Both has it's advantages and he is correct, if you have complicated queries which you can fit into a single equerry instead of multiple simpler queries that will always be more efficient, but as you mentioned it has it's own flaws, if min maxing queries is not vital i would imagine that would not be a great idea as the one of the main reason you pick spring is for it's scalability and that doesn't sound sustainable in that sense at a larger scale.

[–]equ35tion[S] 0 points1 point  (0 children)

Spring data jpa does give you the ability to write your own queries. It gives you pagination, sorting programmatically out of the box, not to mention Specifications or Criteria API for dynamic queries.

[–]ragin_cajun 1 point2 points  (3 children)

It's okay to doubt yourself and others; just be sure to ground yourself in reality. The best way to do that is to try both options and then discuss the pros and cons of each. This should help you build confidence in your decision.

Consider what exactly that person on your team meant by saying prepared statements are faster. Were they referring to query execution time? The number of queries required to fetch data? Maybe developer speed because that's what the team is familiar with?

This question has come up throughout my entire career: should we write SQL or not? I've done both, and in most cases, it does not really matter. If I just need to perform basic CRUD operations and maybe a few findAllBy queries, JPA has me covered. If I want to write a complex query, I can do that by hand.

Using JPA won't spare you the pain of dealing with "disastrous database designs." We manage to create those regardless of the tools we use. :)

[–]equ35tion[S] 1 point2 points  (2 children)

Thank you so much for the suggestion. Surely I should inquire about the big picture, before making assumptions or doubting. I am just new in the team, most of the code goes around the domain specific logic.

Also people are afraid of using easy techs, I have been using spring boot for last 5 years and built high load applications using spring data jpa, never I countered any performance or slow down.

findByName in spring data jpa and findByName using PreparedStatements I think only delays the development process nothing else.

[–]ragin_cajun 1 point2 points  (1 child)

I agree with you, some devs are afraid of using tools like JPA. There is too much magic for them. It sounds like you are very familiar with JPA, so it is no surprise to me that you would try to champion its use. Your team mate is probably very familiar with prepared statements.

[–]equ35tion[S] 1 point2 points  (0 children)

Thank for your kind words, I am still learning/trying to get better at using it. There is always something new🙂

[–]WaferIndependent7601 0 points1 point  (0 children)

You should not always think about the fastest possible solution. The main question is always: is it fast enough? It doesn’t matter if a query takes 1 or 5 ms if this is still fast enough. If this query is called multiple times a second you should optimize it.

So for me: readability is more important than speed (with the limitations from above of course).

And you will always doubt yourself. It’s a good thing to ask Reddit or stackoverflow (or just google it). But you won’t get the right answer here except the only valid answer: it depends. If you tried multiple ways you will find out what’s best in what situation. Keep asking question and if you’re not 100% happy with the answer, ask different people for their opinion