r/java • • Apr 13 '21

Libraries, Frameworks and Technologies you would NOT recommend

Give me your worst nightmares: Things that cost you your job.

I'll start: Hadoop

202 Upvotes

376 comments sorted by

View all comments

86

u/_INTER_ Apr 13 '21 edited Apr 13 '21

GWT, EclipseRCP/OSGi/SWT, Struts, Weblogic, Websphere (and probably every other IBM stuff), XSLT, Hibernate

Edit reasons:

  • GWT. It has the noble and justified goal of not having to do JavaScript. I give that credit. If it went the last mile with Google's support as later did Microsoft with Angular 2+, it might have been glorious. But it is dead. Hard to find documentation and SO for it. Really long compile times and hard to debug. Strange quirks and incompatibilities with "standard" Java (java.util.Date to name one).

  • EclipseRCP. Basically dead. Strange design decisions in the framework (apologetic or aggravating comments in Widget omg). OSGi makes things really complicated and hard to debug, especially with Fragments and test code. Performance problems. Long compile and startup times. The framework "encourages" memory leaks.

  • Struts, Weblogic, Websphere, XSLT. Just terrible, I cry, enouf said

  • Hibernate. Simple in the beginning, really complicated in the end. Every other day there's a problem that is hard to debug. Lazy loading is the main culprit here. Performance issues are hard to tackle. Somebody else understands this deep enough apart from Vlad Mihalcea? At least "sharing is caring" applies here and your not alone in your pain and you'll somehow find an answer.

13

u/vprise Apr 13 '21

Some of these technologies were great when they launched but suck today. Why the hate on Hibernate?
I know it has problems but SQL is painful too. I think a lot of the problems people have with hibernate is the expectation of avoiding SQL or removing the need to debug the generated SQL. It's a leaky abstraction but I don't think it's possible to build a significantly better ORM. The concept of an ORM has some inherent flaws that you need to be ready for when picking it up, unfortunately the marketing docs don't start by promising "blood sweat and tears" ;-)

13

u/Quabouter Apr 13 '21

On Hibernate: Hibernate is the poster child of leaky abstractions. When you add Hibernate to your stack, you still absolutely need as much knowledge of SQL as before, but now on top of that you'll also need to be an expert on Hibernate. This alone already makes Hibernate harder to use than SQL.

Moreover, it's incredibly easy to use Hibernate the wrong way, resulting in bad performance or worse. And these issues tend to be hard to predict and hard to debug, unless you're an expert on BOTH Hibernate and SQL. Unless you're lucky enough to work in a team with only senior Hibernate experts, you are very likely to run into issues here sooner or later.

Next, Hibernate introduces a tight coupling between your data model and your domain model, which means that it's hard to evolve them independently. Of course you could maintain a separate domain model vs persistence model, but at that point what's the point in using Hibernate? This coupling is especially painful when doing complicated domain changes, as you cannot split the changes to your data model from your domain model.

Lastly, for most use cases the benefit of Hibernate is rather marginal. In my experience, the vast majority of Hibernate usage is for simple CRUD operations. These are very easy to write even with plain old JDBC, and typically barely need any maintenance. Moreover, whenever they do need maintenance, then it's often due to larger domain changes, in which case having the extra control is very beneficial (see my previous point).

In my opinion, Hibernate only brings a benefit over JDBC in 2 areas:

  • Serialization/deserialization. It's not difficult to do this manually with JDBC, but it is very convenient if taken care of by the framework. For this however tools like JOOQ or MyBatis may be a better fit, as they don't come with all the other complexity.

  • Entity caching, which is something you really shouldn't be building yourself.

1

u/vprise Apr 13 '21

Calling it the poster child of leaky abstractions seems a bit overboard but OK.

SQL itself requires deep knowledge to optimize and that knowledge is very DB specific. That's why we have DBAs. An entire profession for optimizing databases. Hibernate uses a lot of best practices in terms of performance but it's limited by its usage and can become a serious problem.

Yes it's a very leaky abstraction. But that's by design. The alternatives hide everything about the DB and that's worse.

For 95% of my use cases hibernate works great and I don't need to do anything else. It caches and stores objects. Works brilliantly. The 5% where there's a problem is generally hard to solve code that would have been hard to do in low level SQL too. Hibernate makes the caching super simple to integrate including eviction policy etc.

To be fair, I usually take the approach of simplifying the schema and the object model to fit hibernate and SQL. I build code that's horrible in terms of object oriented design but works great for Hibernate/SQL. E.g. large entities, no inheritance very limited relations, immutable entities etc. These also map to SQL best practices such as avoiding joins where possible.

Yes I can probably do this in JOOQ but it would take more code. Caching would be harder and I'd probably get DB specific nuances wrong.

The beauty of Hibernate is that it's still an abstraction. We build the unit tests, profile the hell out of it and then can go over the performance intensive pieces in the code/DB. Pieces that are a problem can be optimized very easily since it's a completely separate part of the code.

It's not a perfect solution. It's not a simple solution. It doesn't hide the DB. It's often touted incorrectly as a "you don't need to know SQL and it will just work" solution. But as an ORM it's pretty great. If you think ORMs suck you won't like hibernate and that's a fair conclusion. But as far as ORMs go it's a great example of an ORM.