News for hackers. Stuff that matters.
Re:SQL is 43 years old – Here’s why we still use it today by matwood on Tuesday May 02, 2017 @10:58AM (#14246857)
I'd be curious about the size of the systems you have used with Hibernate. Do you know off the top of your head what will cause Hibernate to issue a flush? How about the order of operations in a batch? I've read the entire Hibernate book multiple times while trying to squeeze out speed, and finally decided enough.

The problem with Hibernate is I have to learn all of these Hibernate quirks to maybe get decent speed out of a system, when I could have just written SQL and been done. This isn't even including debugging when Hibernate decides to issue N+1s.

Re:SQL is 43 years old – Here’s why we still use it today by mindcrime on Tuesday May 02, 2017 @12:46PM (#14248014)
I'd be curious about the size of the systems you have used with Hibernate.

I wouldn't even know what metric to use to quantify that. Number of tables? On the order of hundreds, probably low hundreds... definitely not thousands.

It may just be that I've been lucky in that the data models I've worked with have been things that map well to using Hibernate. I will say that I haven't worked with a lot of data models where you need more than 3 or 4 joins in any given query. I know some people write far more complex queries than that, and maybe those are the kinds of scenarios that Hibernate doesn't handle well?

The problem with Hibernate is I have to learn all of these Hibernate quirks to maybe get decent speed out of a system, when I could have just written SQL and been done

Do you hand-roll your own caching mechanism when just writing plain SQL?

Re:SQL is 43 years old – Here’s why we still use it today by matwood on Tuesday May 02, 2017 @01:18PM (#14248348)
> Do you hand-roll your own caching mechanism when just writing plain SQL?

Using something like jOOQ has meant I rarely need any caching, unlike Hibernate where caching almost seems required.

Re:SQL is 43 years old – Here’s why we still use it today by mindcrime on Tuesday May 02, 2017 @01:22PM (#14248399)
Interesting. I've never used jOOQ, but I'll give it a look. Hibernate has worked well for me, but I'm not dogmatic about it. Always interested to try new tools.
Re:SQL is 43 years old – Here’s why we still use it today by matwood on Tuesday May 02, 2017 @01:39PM (#14248600)
I've been writing SQL for almost 20 years, so the pain for me is the grunt mapping of data to and from. jOOQ does much of the grunt work of mapping, and lets me write typed SQL that it smartly translates to queries. More advanced features like various types of fetch make my job even easier.

https://www.jooq.org/doc/3.9/manual-single-page/#arrays-maps...

Re:SQL is 43 years old – Here’s why we still use it today by cygned on Tuesday May 02, 2017 @11:26AM (#14247134)
I had to use Hibernate in a project. We were loading an entity from the database, someone invoked a setter and the set value was updated in the database automatically. Totally blew my mind.

Never touched it again since then (not doing much Java anyway).

Re:SQL is 43 years old – Here’s why we still use it today by cakes on Tuesday May 02, 2017 @11:42AM (#14247287)
This mirrors the experience I have as well. I (currently) don't know what will cause Hibernate to flush but I certainly do know that I had to know this exactly and had to do some really painful debugging at points. The worst one I was on was just early prototyping of an app that used Hibernate and we had so many problems with performance and Hibernate(isms) that the whole thing seemed destined to fail even though our use case was exactly what ORM/Hibernate are for...yet we still have to control when changed flushed because otherwise things would get wonky really quickly.
Re:SQL is 43 years old – Here’s why we still use it today by dunham on Tuesday May 02, 2017 @01:02PM (#14248173)
Yeah, profiling helps a little. It taught me that queries flush (and you can easily go n^2 from that if you're not careful).

More recently, we've had n+1 issues (putting a printing breakpoint in EntityType.loadByUniqueKey helped me track down where). My hack to get around that was to do a bulk Criteria query up front to pre-load the session cache with the entities that were being fetched one at a time.

There were a lot of quirks that I've had to learn over the last decade, and I'm still discovering more.

Re:SQL is 43 years old – Here’s why we still use it today by gerbilly on Tuesday May 02, 2017 @11:10AM (#14246974)
Speed? I found Hibernate is great for CRUD.

Like where you have dozens and dozens of domain objects that you want to persist, and you don't want to spend all your time writing DAO code with SQL in in that is all the same but different.

Enterprise applications are rife with those.

For speed write some hand written SQL to handle those few cases (like batch imports maybe).

Also I found a handy rule:

Only create an association between entities when the entity makes no sense without the other.

For all other cases split them up and perhaps create aggregates by hand.

Re:SQL is 43 years old – Here’s why we still use it today by mindcrime on Tuesday May 02, 2017 @12:47PM (#14248029)
That jibes with my experience. We don't have tons of complicated associations, and do a lot of fairly straightforward CRUD operations. Maybe that's just the sweet spot for using Hibernate.