IIRC, it does that if you use Lists instead of Sets.
https://dzone.com/articles/best-performance-practices-for-hi...
E.g. If say
Person {
id: Integer,
name: String
}
Let's say I have some entity that stores Persons as HashSet. If I add them before saving, their hash set is taken without Id.Id can be automatically generated by Hibernate on save/create.
After save the Id now has a new value. I.e. its hash differs from when it was saved.
Boom. You have HashSet with Zombie entries. That are technically that you can't fetch actually.
Yeah, it seems a little bonkers on first glance and I haven't ever dug in to see if there was a justifiable reason or not.
IIRC, if you just need ordering, you could just use an SortedSet. I think technically lists are for when you need ordering and duplicates.
There are so many rules to remember for something that is supposed to make SQL integration natural.
All I have to do to create a new table is define a class with some attributes and the corresponding SQL migration, I don't even have to annotate anything. To create a new row I just do new Table(attr1: expression1, attr2: expression2).save() and I am done.
Compare that to the usual mess of writing down the same column name four times with raw SQL (1. to reference the column, 2. to set the column value with a named parameter, 3. to set the named parameter, 4. declare the variable you wanted to save in the first place).
Of course, I'm not using Hibernate directly, that would be foolish. Instead I am simply using Gorm to wrap the awful parts of Hibernate (the irony).
Anyway - I’m definitely not advocating for raw JDBC, there are lots of libraries you can use to reduce the complexity of the integration with the database, it’s just that JPA is not (IMO) one of them.
One thing I don’t understand about your comment it “the usual mess of writing down the column name four times with raw SQL” - when is this necessary? ’update table set column=? where key=?’ has no duplicate names. Can you give an example?
I’m intrigued by how your solution to JPA’s verbosity problem is to add another layer, while mine is to remove one!
But we found even in simple applications with a dozen tables, the generated SQL was suboptimal. For example, to delete the children of a parent row resulted in a DELETE statement for each child row. I’m sure there are loads of good reasons why it did that, but it’a not something that you’d even consider in pure SQL.
The systems I build these days tend to put 100% of the database logic in the database using (you guessed it) plPGSQL, and leave Java (or actually Go these days) to do the non database transforms, networking etc. you could say that I replaced learning about JPA with learning more about the insane capabilities of my database.
I’m sure you (and half of HN) are gagging right now, but I know I’m not alone, and I’ll take 75% fewer LOC and 1-2 orders of magnitude performance improvement over JPA any day.