Live data from Hacker News

Problems with JPA/Hibernate

stemlaur.com

21–30 of 195 posts

Re: Problems with JPA/Hibernate

#21
post #9

From my experience ORMs are good time savers when you have relatively simple query needs, but fall down when things get really complex.

Where simple already doesn't include pagination, when all those frameworks generate OFFSET queries that cause the equivalent of a full table scan when someone clicks "last page".

Re: Problems with JPA/Hibernate

#22
post #9

From my experience ORMs are good time savers when you have relatively simple query needs, but fall down when things get really complex.

Nothing prevents you from using raw SQL queries with Hibernate. HQL is just a convenient superset.

Actually mixing raw queries with JPQL/Hibernate queries is the worst of all worlds. To get it right, you will end up making explicit calls to let the EntityManager know what you want each side to be doing to play nice.

Re: Problems with JPA/Hibernate

#23
post #6

This article is... Questionable at best. I don't think any of this is an argument against JPA, except that the author doesn't like how it works? I also suspect the author doesn't know hibernate that well. For instance selecting just the fields you need is relatively simple with JPQL: SELECT i.url FROM Image i WHERE i.id = ...

that looks very like sql, whats the benefit then ? X amount of dependencies to write almost sql ?

Re: Problems with JPA/Hibernate

#24
I largely agree that JPA is a maddening mess[0]. However, this sentence caught my eye:

> I love open source, really, but big companies sponsoring open-source projects get most of their income from support or third party tools.

I work for VMware and consequently take some interest as to how my salary comes into being.

If you think VMware makes "most of its income" from supporting Spring, then I think I'd encourage you to spend some time at the investor relations site[0] reading any of the annual or quarterly reports. I'd advise the same for Oracle and Red Hat/IBM.

[0] The advice to use emails or SSNs as primary keys, though: yikes.

[1] https://ir.vmware.com/

Re: Problems with JPA/Hibernate

#25
I disagree with this bit:

    A User can be considered unique in one context by its email address, or by its social security number
Personally, I'm a fan of giving everything a random UUID, because it's more flexible. It's random and impossible to guess, it scales well because there's no central bottleneck like with an autoincrement, and it's future proof and flexible.

What happens when the user changes the email address? What if the social security number changes, because it was wrong or because it actually changes? What if the original unique identifier wasn't a good choice? What if we decide that the user can have multiple email addresses? Then you may end up having to restructure the entire database, which will be a very annoying thing to do. What if you implement additional rules for what an email is allowed to look like and now the constraint fails for existing users, and this correction needs to be propagated to millions of already existing rows?

Real-life personal data is weird and fuzzy. They can violate seemingly sensible rules like being unique, unchanging, or conforming to any rule whatsoever. Best not to let them spread all over the DB and cause trouble later.

Instead, you could just have a random ID that doesn't mean anything and therefore can stay fixed forever, and any user-related metadata stays in the user table, where it can be modified as needed. Plus an UUID is a fixed 16 bytes, which is easy and efficient to deal with.

Re: Problems with JPA/Hibernate

#26

Earlier quoted context omitted.

Nothing prevents you from using raw SQL queries with Hibernate. HQL is just a convenient superset.

Actually mixing raw queries with JPQL/Hibernate queries is the worst of all worlds. To get it right, you will end up making explicit calls to let the EntityManager know what you want each side to be doing to play nice.

I've never hit such a bug. Can you expand on what (and when) added complexity would a raw query have versus a raw query without hibernate?

Re: Problems with JPA/Hibernate

#27
post #9

From my experience ORMs are good time savers when you have relatively simple query needs, but fall down when things get really complex.

Nothing prevents you from using raw SQL queries with Hibernate. HQL is just a convenient superset.

whats the advantage of that ?

Re: Problems with JPA/Hibernate

#29

Earlier quoted context omitted.

One benefit I've been seeing with server side JS is from FAAS like Lamba which can serve unpredictable loads very inexpensively.

How is that a benefit specific to JS? Don't those platforms generally support Java as well?

They do but the Java ecosystem takes a hit here, with many libraries being slow to initialize. The slower it takes to startup, the longer it takes to absorb the new load, to the point where you either keep some headroom (IOW, waste $$$), or try to predict load (complex, also wastes $$$).

There are attempts to fix this with e.g. Graal, which effectively does the expensive initialization and reflection at compile time, but there are so many downsides and pitfalls right now with Graal that I don't consider it a serious solution to the problem. It's basically creating a new ecosystem, which means one primary motivation--to take advantage of the Java ecosystem--is much less compelling.

This isn't constrained to the public ecosystem, lots of companies have their own internal libraries, and Java makes it very easy and even encourages doing lots of expensive things at startup, like classpath scanning and pre-caching things. For a long time, Java made explicit decisions to de-prioritize startup time to improve maintainability (reflection/scanning/dynamic classloading) and runtime performance (e.g JIT). This tradeoff doesn't work out so well in a world of ephemeral processes that come and go as demand changes.

I guess what's specific to JS, Go, Python, et al is the cultural emphasis on fast startup. Interestingly these all come from different constraints but the net result is that, in general, you can go from cold to serving traffic much faster than with Java, with a lot less effort.

Post reply on HN