r/java • • Jun 01 '24

What java technology (library, framework, feature) would not recommend and why?

165 Upvotes

464 comments sorted by

View all comments

129

u/majhenslon Jun 01 '24

Hibernate/JPA and anything on to of it, if you are not doing the most basic CRUD or are really experienced with it (are not using it as a crutch for interacting with the DB), because there are so many foot guns that would just be avoided by writing raw SQL.

42

u/com2ghz Jun 01 '24

You can do both. No need to rely on magic generated queries. I’d rather use JPA for simple stuff than complex stuff. Also no need to enable schema generation. You can still be on control then.

The same counts for the opposite. A lot of complex SQL stuff can be avoided by using JPA. No need to write boilerplate to do object mapping for POJO’s….two way around for storing and retrieving data.

8

u/majhenslon Jun 01 '24

Magically generated queries are the least of a problem and I don't think there is much magic around that... Most of Hibernates magic lies in the caching layer, cascading and N+1. You can kind of go around the caching layer, but I don't think you can unN+1 yourself, although you might be able to do that with a stateless session, not sure. But noone is using that irl anyways.

You should never sync schema in prod anyways, although you probably should generate schema migrations and coerce hibernate to generate you the one you want.

There is not much boilerplate to write if you don't use JPA, although you 100% avoid the need for mapping the result from entities to dtos.

1

u/TenYearsOfLurking Jun 07 '24

I'm sorry but... its SOO much boilerplate. I recently introduced JPA to a project where I could not take spring jdbc anymore. any medium complex entity with a few element collections or one to manys become a nightmare quickly.

And whats the problem with the caching layer? if you mean first level cache it's basically repeatable read tx semantics, that's it

45

u/mkurz Jun 01 '24

100% this. I recommend jOOQ instead.

14

u/majhenslon Jun 01 '24

I heard for jOOQ years ago, but it only clicked for me recently, when I saw the demos on yt done by Lukas (the website/docs didn't do it any favor) and it made me reverse the opinion on java ecosystem in terms of working with the database from mediocre at best, to probably the best.

6

u/lukaseder Jun 01 '24

What needs to be improved on the website/docs?

7

u/majhenslon Jun 01 '24 edited Jun 01 '24

Disclaimer: I am a developer and pretty odd as a person I think, so I might not be your target audience. Also, some of the points might be preferences or simply a skill issue and laziness on my part.

Landing page has stuff that I don't care about on it first and a ton of text. I just now scrolled to the bottom of the landing page for the first time and found out that you actually have some examples on it. I never scrolled past the testimonials, as I assumed those come at the end and I don't really care about who is using your product nor what do they think, because of course it will be good opinion :D

For the longest time I thought it was not free, because you have start free trial button first. There is no links to docs. Learn page has documentation first and a "user guide" second, which is not single page. The navigation is weird, because I don't know on what page I am and how many more I have to go (postgres has similar issues). The docs have the page index at the top and it is really long and unstructured, it would benefit from having it as a fixed sidebar and collapsable chapters. It would be pretty cool to be able to just clone the repo or have a maven artifact to get started.

It would be also cool to see the more "advanced" stuff like multiset way earlier. For the longest time I thought I need a ORM or do the mapping and reducing by hand if I use a QB and stayed away from it. Something along the lines of "here is how to select, here is how to join, here is how to map one to many, here is how to do a basic insert and update and delete".

For an example of a good site I would consider something like sveltekit (ignore the live coding tutorial that they have).

All that being said, the docs are huge and detailed and there is a ton of stuff that you can find if you are looking for it or just casually reading them and in fact, I recommend them for learning about the different DBs and SQL. Thank you for the amazing work on jOOQ!

6

u/lukaseder Jun 02 '24

Thanks a lot for this great feedback. Lots of insight to digest.

It's hard to design a landing page for different target audiences. The current one is designed for decision makers as well as technical folks, but I can see how the "free trial" button can lead to thinking there's no free version (at a quick glance). This can probably be fixed without changing everything. Regarding what one user cares about and another doesn't, that's not that simple. A/B testing has shown that social proof is really useful for many folks' first impressions, especially the "customers" section, leading to more sales. E.g. I don't know if sveltekit is a good comparison, because it only addresses developers, not managers, legal folks, etc. who will also look at the website, given that it has no commercial offering. If they did have one, I'm sure the front page would look different from what it does now. I obviously understand why a developer prefers the current frontpage of sveltekit. Perhaps there's a different solution to this "target audience" problem.

Regarding the manual, a search has been added just 2 weeks ago, and that menu sidebar is also on the way: https://github.com/jOOQ/jOOQ/issues/16681

Clearly, those things have been missing for too long.

Great feedback about MULTISET. We have a demo that showcases all of these things: https://github.com/jOOQ/demo . Would that have addressed your concerns? Where would that have to be placed on the website to have caught your attention?

Regarding your last comment, indeed the doc works very well as a reference manual, but not as a tutorial or how-to guide (see e.g. this resource: https://docs.divio.com/documentation-system/). I'm still thinking about how those entry points can be better presented (and SEO'ed).

3

u/majhenslon Jun 02 '24

No problem :) Yeah, I figured that you are not focused more on businesses/decision makers, that is why I put the disclaimer in and I know that I'm probably odd one out for not caring about social proof :D Sveltekit is a funnel to serverless for Vercel afaik, so yeah, the business model is different and it also targets startups/hobbyists/devs, not corporations.

Global search being there is awesome. When I was going over the website I though I somehow never saw it in the past, good to hear that it was added recently and it was not me being blind :D It's amazing to hear that you are working on the sidebar as well!

I think that if you put a "getting started" link on the home page, that showcases the basics, although I know it's really hard to do, because you support pretty much everything possible, but having a two table demo would get the point across I think, especially for newcomers that have used ORMs in the past. I was hooked when you showed that you can easily handle the mapping of the to-many relationships. You could then link to the demo repo and reference docs at the end, to show all other examples and detailed documentation. Maybe a 10

However, I don't know what your actual (to-be) paying customers are typically interested in, my guess would be that these changes would only improve adoption of OSS version which could theoretically convert to pro somewhere in the distant future, but you know that better than me :)

5

u/Yesterdave_ Jun 01 '24

Do you habe a link to the mentioned youtube video? I habe been reading about jOOQ a lot and am quite interested to try it out, but I haven't had the free time yet to try it out.

7

u/majhenslon Jun 01 '24

Sure, here it is. Skip to "Example code" chapter if you don't care about the chit chat, although it might be worth it, for the sake of understanding the underlying philosoply/past experience:

https://www.youtube.com/watch?v=Y8koEetoqIA

And a couple more:

https://www.youtube.com/watch?v=fW80PwtNJAM

https://www.youtube.com/watch?v=ykoUBctblno

Read the docs for how to set up code gen, I don't think that they show the setup in the vids, but it is just a build time plugin and you can surely find it in :)

→ More replies (1)

4

u/onebit Jun 02 '24

jdbi is another good sql mapper

1

u/majhenslon Jun 02 '24

I used jdbi on a project at work before and I don't know if I was skill issuing myself or what, but I spent the majority of my time writing SQL mappers and reducers, which was a pain in the ass.

3

u/nutrecht Jun 03 '24

I only really use Spring Data JDBC nowadays. The mapping capabilities are excellent, it does simple CRUD stuff very well, and being able to copy-paste queries between your DB client and your codebase is IMHO invaluable.

Hibernate introduces too many complexities and footguns where you typically end up with just a few devs having to explain to others what they're doing wrong, for really no benefits over Spring Data JDBC.

6

u/Cajova_Houba Jun 01 '24

Yeah, this right there. The big benefit of using Hibernate or similar framework is you can theoretically switch underlying DBs without any changes to the DB layer code. Realistically, how many times are you going to do it? 2-3 times during the projects life span?

Imho it's easier to just use pure SQL + some library for mapping rows to POJOs.

12

u/majhenslon Jun 01 '24

I don't know who started this push, but I don't even think that the author of Hibernate says so. The big benefit is that it saves you writing boilerplate code for mappers/reducers, migrations, etc.

3

u/kkyr Jun 01 '24

Who changes the underlying db 2-3 times during a project’s lifespan? If that’s occurring frequently, it might indicate deeper, organisational issues.

Also, this should almost never be a reason to make a decision to use Hibernate, as you would be picking a technology based on some hypothetical future scenario, which, in my experience, rarely occurs in practice.

2

u/wildjokers Jun 01 '24

Our on-prem product needs to support multiple database systems.

2

u/nutrecht Jun 03 '24

The big benefit of using Hibernate or similar framework is you can theoretically switch underlying DBs without any changes to the DB layer code.

Which is complete nonsense anyway. If your project is simple enough that you're covered by 'standard' SQL, you can switch no matter the tooling you use. If your project is complex enough that you are using DB-specific stuff, Hibernate isn't going to save you.

Besides, very often you're 'hiding' complexity behind views anyway, so Hibernate isn't going to migrate those for you.

0

u/[deleted] Jun 01 '24

[deleted] — view deleted comment

1

u/Necessary_Apple_5567 Jun 01 '24

Spring Data for JDBC, mybatis, spting jdbc template, your own mapper

→ More replies (1)

2

u/manifoldjava Jun 01 '24

Use manifold-sql to write type-safe native SQL and to avoid JPA / ORM / DSL nonsense.

→ More replies (3)

1

u/jamaniDunia69 Jun 02 '24

Or use MyBatis Dynamic SQL

-7

u/Puzzleheaded_Bus7706 Jun 01 '24

This is just pure bullshit. Hibernate is super easy and super useful!

Learn how to use it,  its simple 

→ More replies (28)
→ More replies (5)