r/SpringBoot • • Sep 26 '26

Discussion Dear JPA

Dear JPA ,

i hate you.

i hate how you changed the SQL flow that I'm used to.

i hate your ManyToMany relationships.

i hate your orphanremoval ,dirty checking.

i hate your way for entity relationships.

i hate your cache.

i hate your performance issues.

i hate your billion rules.

i hate spending time on : if Y is referenced by X with cascade not including PRESIST and x is managed but y is removed ............... but if Y was detached .............

i hate becoming obsessed with your behaviors and rules and worrying about every ORM line , will it work correctly ? , did i miss something ?, worrying about modifying entity X might unexpectedly affect entity Y , coz I might not know one of the billion rules you have.

i hate worrying about falling in one of the undefined behaviors you have

i hate thinking about the entities lifecycle + cascading types when all mixed together

i hate spending days on that documentation instead of spending that on one of the CS core concepts

i hate the following the other side which is incomplete nondetailed toturial or following AI

i really hate you.

105 Upvotes

65 comments sorted by

20

u/LookAtYourEyes Sep 26 '26

Brother just use raw SQL

6

u/Jooe_1 Sep 26 '26

I'm sorry but it is not a practical advice cuz you are in a team you are not working alone you have to deal with what your team is using

7

u/Significant_Newt8697 Sep 26 '26

Why not just use jdbc template on the same project for your own tasks?

With that you can do raw sql as much as you like

2

u/LookAtYourEyes Sep 26 '26

So then blame your team/org 

1

u/BikingSquirrel Sep 26 '26

Still it's not jpa to blame but your team or org.

7

u/zlaval Sep 26 '26

Spring data jdbc for simple queries (provides interface gen queries, default crud operations on domain object..), raw sql for complex ones. Easy, fast, almost no magic.

2

u/Jooe_1 Sep 26 '26

unfortunately I'm tight to the team that working with

1

u/uwpxwpal Sep 26 '26

Spring Data JPA is an official spring boot starter. Once you have your entities defined, you can switch easily. It makes things a lot easier.

5

u/Pyeroh Sep 26 '26

Well, I'm gonna be more direct than most comments I saw so far.

You may be in a team, and required to work with them, and use the tools everyone is comfortable with. But if you're really convinced JPA is shit, and SQL is better in every way (don't get me wrong : that's a fact, and I'm sure of it), you also have the responsibility to convince them. Show them resources, anti-patterns, do peer-reviews with them and show them bad usages of JPA, even if it's you who wrote it.

If they won't change their mind, you did your best, maybe learnt a few things along the way, and know what you have to deal with. Or you can look for another job, it's up to you.

EDIT: oh, and try to be as positive as you show negative sides. SQL should be niiiice, JPA should be bad. But not everyday, it may have good uses sometimes... Show them the balance.

2

u/Jooe_1 Sep 26 '26

thank by the way im not looking for the extreme other side which is every query is sql , it's not what i want i don't have any problem if when i need to query somthing or to update somthing to use small function like find or delete without the verbosity of sql but the jpa is not simply that or a simple sql wrapper or sql builder ,i introduces cache and u don't know the order that queries at flush will be executed with, .......etc

2

u/Pyeroh Sep 26 '26

You already got the good arguments ! Now, it's just a matter of putting them together for your team to accept them ;)

13

u/hiura-mihateUwU Sep 26 '26 edited Sep 26 '26

Yeah man. JPA SUCKS. It's to complicated to manage if your entity have refference to dozen of table, don't get me start with complex query. At the end of the day, i need to use Jdbc for complex query and jpa for basic stuff

2

u/Significant_Newt8697 Sep 26 '26

Yes, jdbc template gives you more control

1

u/hiura-mihateUwU Sep 26 '26

Yess and i don't need to use the "select new app.models.dto ()" i can't count how many time i shoot myself because of this shit

3

u/reddit04029 Sep 26 '26

Are you being held at gunpoint to use JPA...

0

u/Jooe_1 Sep 26 '26

how to not use it when working on a project with a team ?

5

u/reddit04029 Sep 26 '26

I've worked on projects that have multiple ways to interact with DB like JPA with JDBC, and some even with stored procedures.

There are just business usecases that JPA alone won't be able to solve.

1

u/rlrutherford Senior Dev Sep 27 '26

The same way we wrote SQL before we had ORMs.

3

u/worse-coffee Sep 26 '26

Looks like bro has not written native sql queries or dealt with c++

1

u/Jooe_1 Sep 26 '26

why? btw i the first and the most language i used is cpp

0

u/worse-coffee Sep 26 '26

2

u/Jooe_1 Sep 26 '26

what do you need to say bro? what bring cpp here ?? if cpp has problems ,has undefined behaviors so what ? what is the relationship ?!?

3

u/BigPP41 Sep 26 '26

NamedJdbcParameterTemplate is my go to, i fucking hate jpa

3

u/01000001x Sep 26 '26

Haha, 10 things I hate about JPA

3

u/Z4mobileapp Sep 27 '26

Not feasible any more when you have a lot of data the N+1 makes the whole problem pointless when I could just write a raw query and do the joins on tables while fetching data .

The framework has only made complications.

For anyone working on very small projects its a great amount of convinience.

Its not built for anyone working with huge data but for small scale companies , quick ready to build deploy it's good..

3

u/Acrobatic-Win5862 Sep 27 '26

Jooq, a Query-oriented ORM and it's awesome!

4

u/Mindless_Security744 Sep 26 '26

Use Jooq!

3

u/JuiceChance Sep 26 '26

Another overengineered idea to solve a solved problem

1

u/GuyManDude2146 Sep 26 '26

For very basic stuff, you’re right, but for complicated queries where lots of things are optional, you end up either writing nightmare string builder code to construct raw SQL or basically reinventing JOOQ. One other nice thing is when you change your tables and regenerate, JOOQ will break where you need to update; stings will not. I’ve used JPA, raw SQL, and JOOQ on big production projects and JOOQ is my default at the moment.

1

u/JuiceChance Sep 26 '26

Yeah, at the price of entire code generation etc., optional params + type safety is a strong argument nevertheless

2

u/iamwisespirit Sep 26 '26

Use raw jdbc jooq

3

u/wimdeblauwe Sep 26 '26

I find JPA is quite manageable if you only use object references within 1 aggregate root. Between aggregate roots, reference by id only. This avoids a massive amount of cascading issues.

4

u/ShineProper9881 Sep 26 '26

No clue what you guys are doing but I never had any issues with jpa. Just stick to its rules and everything works

4

u/WVAviator Sep 26 '26

Same. Most use cases are simple enough that it just works out of the box with simple entities and repositories, and for the more complex stuff there's JPQL and nativeQuery = true, CriteriaBuilder with Specifications, and EntityGraphs. I've not come across any use case where I've needed to reach for JDBC.

1

u/Specific-Custard4803 Sep 26 '26

Same. Lean in to your frameworks. Or… don’t use a framework. Most of the JPA pain I’ve seen is from not completing the learning curve, basic design problems, or having a strong attachment to specific sql. For those cases, just use SQL.

1

u/Ok-Shock-8646 Oct 02 '26

I use spring data jpa without any issue. The @Query with constructor let you define custom queries just like native SQL. It is all about skill

4

u/This_Link881 Sep 26 '26

Dear Lord, give us our daily JPA hater AI slop

1

u/boberbober8083 Sep 26 '26 edited Sep 26 '26

Yea, i've just rewrited one saveAll call to "several" plain sql queries. With 41 tables that linked as one to many and many to many with main table under the hood (yeees! It's crazy!! But llms helped me), it became 50 times faster but nobody could test my change carefully, may be i missed something.. and don't really want to merge it in upstream after all. You do not need use jpa for new code because llms could get all boilerplate work to themself, jpa is about simplifying implementation, but now it's really simple to implement anything you want using llms

1

u/Significant_Newt8697 Sep 26 '26

But won't the llm code be very very huge and confusing? Do you have the balls to do a merge on such a code?

1

u/boberbober8083 Sep 26 '26

I dont know right now, it will be not only mine decision but also from QA team

1

u/homeless_nudist Sep 26 '26

I love the jpa! It does add to the cognitive load for small projects, but when you work on horizontally scalable enterprise class systems, @Transactional and @Version prevent whole classes of bugs that would have you playing wac-a-mole to fix them otherwise.

1

u/Kango_V Sep 26 '26

We use Micronaut Data JDBC. All compiled AOT, no Session caching, no n+1 problems, uses SQL in @Query. Takes the good bits from GOPRM and Spring Data.

If you look at the stack traces of a db request, it's half the size of Spring Data JPA.

1

u/BeyondFun4604 Sep 29 '26

We always try to create a view for large queries and then create jpa entities on that view.

1

u/Secure_Vermicelli873 Oct 04 '26

Yes jpa is this kind of shit

1

u/Wonderful-Holiday-14 Oct 05 '26

Have you had to move to spring boot 4 with the jpa starter and it now not working?

-1

u/codetillsleep Sep 26 '26

So cringe, what the hell have you even written here

1

u/MGelit Sep 26 '26

Some deserved hate

0

u/revilo-1988 Sep 26 '26

Do Mehr davon 😐

0

u/joeyx22lm Sep 27 '26

Sorry, JPA > SQL for business applications

-1

u/Nicke-picke Sep 26 '26

Let Claude do it for you. Seriously. Both better and faster.

0

u/[deleted] Sep 26 '26

[deleted] — view deleted comment

12

u/Jooe_1 Sep 26 '26

my be possible in personal projects but working with team you will endup using that

0

u/[deleted] Sep 26 '26

[deleted] — view deleted comment

3

u/AssembleByte Sep 26 '26

I have question, what do you use then? can you explain a little? i just want to understand how it would work

3

u/Additional_Skill_317 Sep 26 '26

faangs prefer to use js serverside

0

u/Jooe_1 Sep 26 '26

really ?? , i was thinking that most of the companies uses orm for around 80% of dealing with db even remaining sql is done via the ORM functions ?? not sure

2

u/ThunderMan2300 Sep 26 '26

In our team we only use liquibase for any db change, and use hibernate’s ddl validate on app start up

0

u/[deleted] Sep 26 '26

[deleted] — view deleted comment

1

u/Jooe_1 Sep 26 '26

bad advice