New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable the implicit cascading delete for Spring data jpa #11664
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Although this isn't a breaking change, it's nonetheless something we need to document in https://github.com/quarkusio/quarkus/wiki/Migration-Guide-1.8 |
Ok, I will fix also the failing check |
066d05f
to
e6e77b7
Compare
to add to the migration guide: |
Hi @aureamunoz & @geoand, thanks for preparing the fix so fast. Does calling getEntityManager() in a loop have some additional cost that could be made smaller by caching the found instance in a variable? |
Compared to the cost of going to the database, it's should be negligible |
I've seen massive bottlenecks in older Hibernate versions (for years!) caused by bad synchronization...not actual DB access. But I guess |
OMG I'm dying inside, this is such a rubbish way to use a relational database. (But believable, I guess, given that we're dealing with Spring here.) I would almost say don't try to reproduce the broken semantics of the Spring API but I guess the whole point of this is to do exactly whatever broken stuff they do. Probably (hopefully) people are only using this for tests anyway so perhaps it's not such a big deal. If you did want to do something nonbroken, you could always try looking at the metamodel and detecting the case where there are no cascade-delete associations, and do the nonbroken thing (the bulk delete query) at least in that case. |
@gavinking exactly... When I first implemented this, I definitely didn't expect Spring would be exhibiting this behavior... But we do try to follow the semantics of Spring as much as possible, so that's why we are changing it. And thanks for the suggestion! I really like the idea and I think we should do it. @aureamunoz do you want to tackle that? |
Yes sure, I understand but it still makes me sad. I mean imagine the mind of the person who originally designed this. "Oh Hibernate doesn't have a So Spring. |
Very sad indeed... |
Hi, Yes, I will do it. (I've just seen this messages now!) |
e6e77b7
to
31f8d9e
Compare
Hi! I've just pushed the code with the metamodel checking. I need maybe to add some more test and I have to squash commits but I would like to have your feedback first. WDYT @geoand ? |
...ime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/AbstractJpaOperations.java
Outdated
Show resolved
Hide resolved
@gavinking is the real expert here, I don't think I can really add anything more :) |
So I really wish I could suggest something better than this, but apparently it's the only way: CascadeStyle[] propertyCascadeStyles =
entityManager.unwrap(SessionImplementor.class)
.getEntityPersister( entityClass.getName(), null )
.getPropertyCascadeStyles(); Hibernate really should expose this in a better way. |
Thanks a lot @gavinking! |
31f8d9e
to
7d50b53
Compare
Hi, here is the new code, let me know wdyt when you have some time @geoand @gavinking :-) |
...ime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/AbstractJpaOperations.java
Outdated
Show resolved
Hide resolved
...ime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/AbstractJpaOperations.java
Outdated
Show resolved
Hide resolved
This test fails because we delete here the child entity and the line after the parent one. We don't need anymore to delete manually child entities. WDYT @geoand @gavinking ? Thanks!! |
@aureamunoz I'm a little lost because I'm not sure where is the Spring in that code. |
@aureamunoz that makes sense with this change I think |
7d50b53
to
cf8d7fa
Compare
Hi! The checks passed and I think it's ok for review @geoand @gavinking |
Yes, exactly, we don't want to reproduce that behavior for regular Panache usage, only where we're aiming for strict compatibility with Spring. |
cf8d7fa
to
4e56cf3
Compare
New push adding a test to verify the many-to-many associations and cascade deleting. When you have some spare time it would be cool to have a review! Thanks @gavinking @geoand |
...ime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/AbstractJpaOperations.java
Outdated
Show resolved
Hide resolved
4e56cf3
to
bd72be7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Spring and Quarkus parts look good.
I'll let @gavinking comment on the Hibernate part
.../runtime/src/main/java/io/quarkus/hibernate/orm/panache/runtime/AdditionalJpaOperations.java
Show resolved
Hide resolved
The problem is to detect many-to-many associations that are not set up for cascade delete. Something needs to delete the links from the association table in that case. |
I was looking to see what Spring Data does in this case and I can't much information on how exactly it's done in that case. @gavinking how about we merge this as it seems to handle the typical cascade cases and leave MANY-TO-MANY for if / when someone asks for it? |
My 2 cents: if there is a known limitation, we should document that clearly. |
Yeah, that definitely makes sense |
Hi! |
b725d34
to
2c28df0
Compare
Hi again, I have been working on this, specificly on the I have verified and this is also the behaviour of Spring. So, is this ok for you @gavinking ? |
2c28df0
to
dedc3d4
Compare
what a hell! I've just pushed a refactor for tests that are checking the delete in which they prepare the data to delete in order to not depends on data available on database. Let's see if the CI pass |
1bd5675
to
55c2f43
Compare
test: add test for @many to many association fix: pass entity class test: add and improve tests refactor: rename table refactor: preparing data for deleting tests refactor: refactor in tests fix: clean up the created data
55c2f43
to
0b45b74
Compare
Awesome! unbelieveble! All checks passed, could you please take a look? @gavinking @geoand |
Hey @gavinking , could you please take a look at this if you have some spare time? |
I'm gonna go ahead and merge this one. If we feel it's not right for some deep technical reason, we can always revert as we have plenty of time until the 1.10 release |
fix #11398
@geoand WDYT?