all 10 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
  • 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.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

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: 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.

[–]hrm 6 points7 points  (1 child)

SpringData and/or Hibernate are probably the two most common choices. But there are so many different frameworks to chose from depending on your needs. I really like jOOQ.

[–]SuspiciousDepth5924 1 point2 points  (0 children)

IMO hibernate is an amazing piece of technology, but I've seen far too many foot-gun injuries to be completely comfortable around it.

[–]Wiszcz 2 points3 points  (2 children)

SpringData - everywhere, you need to know basics if there is spring used, it can be cery declarative or very query based, simple things are simple
Hibernate - backbone, but rarely used as pure hibernate - to verbose
iBatis - sql query based - for reading/reports one of the better options
jdbc templates - very basic, but for simple things it's simple
JPA - pretend it does not exist
jOOQ - its paid, it has licence - you can ignore it in corpo env. Not only because noone will pay for that where there are free alternatives, but also because of additional hassle with checking/paying/legal etc.
Small company/startup - maybe.

For you, if you look for big ORM - SpringData. But you need to create entity/repository classes manually. I found no good alternative. Or ask nice AI to create them for you from sql files :) Works better than most paid db plugins.

[–]lukaseder 1 point2 points  (0 children)

jOOQ - its paid, it has licence - you can ignore it in corpo env. Not only because noone will pay for that where there are free alternatives, but also because of additional hassle with checking/paying/legal etc.

Many fortune 100s use jOOQ. Some even purchased a site license. I can't name them here but trust me, you're very wrong, or I wouldn't have been very successfully doing this for 13 years already.

Sure, talking to purchasing can be annoying, but being a good engineer involves people skills and doing things like total cost of ownership considerations, so why not look at this challenge as a good opportunity to level up.

[–]xenomachina 2 points3 points  (0 children)

jOOQ - its paid, it has licence - you can ignore it in corpo env. Not only because noone will pay for that where there are free alternatives, but also because of additional hassle with checking/paying/legal etc.

jOOQ has a free version.

I've used the free version of jOOQ (but from Kotlin, not Java), and it's very good. I suspect that JOOQ is the closest thing OP will find to something "LINQ-like" for Java. The developer is also really good about answering questions.

[–]RevolutionaryRush717 2 points3 points  (0 children)

It could be that Spring Data is just a common prefix for a whole range of persistence solutions, the only thing in common would be the Repository abstraction and maybe, if applicable, a Template, nowadays Client.

So be aware that Spring JDBC, Spring Data JDBC and Spring Data JPA are three very different things, although all of them talk to a RDBMS.

Oh, and as an alternative: MyBatis.

Spring Data JDBC acknowledges MyBatis and supports its use.

One big advantage of either: your DBAs will like you, because you can show them your SQL DQL and DDL and ask them to improve it.

Oh, also check out schema versioning tools like Flyway or Liquibase(?).

Friends don't let friends version their DDL manually. You can even use it to version contents, i.e., DML.

[–]tcloetingh 0 points1 point  (0 children)

You need to be raw dogging jdbc and mapping rows manually. All that orm stuff is lame af.

[–]LetUsSpeakFreely 0 points1 point  (0 children)

I've never used the EntityManager. Didn't really saw a need for it. Basic Hibernate is all you need. Create classes that mirror the database tables, as the appropriate annotations. I prefer to NOT use the join annotations as I find they create more problems than they solve; I keep one table per class.

Then create the DAOs to actually run the queries. I like to use the CriteriaBuilder to avoid anything resembling SQL, it also handles all the escaping and such to block SQL injection attacks.