Skip to content
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

@OnDelete is ignored #145

Open
dkunzler opened this issue Feb 6, 2017 · 8 comments
Open

@OnDelete is ignored #145

dkunzler opened this issue Feb 6, 2017 · 8 comments

Comments

@dkunzler
Copy link

dkunzler commented Feb 6, 2017

Consider the following class (shortened from the original, Tenant is another class):

`
@entity
public class User {
@id
Long id;

@ManyToOne(optional = false)
@OnDelete(action = OnDeleteAction.CASCADE)
Tenant tenant;

}
`

This should make a foreignkey constraint with onDelete="CASCADE" in liquibase. But this isn't the case.
There is just a normal FK constraint without an onDelete.

Therefore deleting a tenant will fail if there are users left. If I let hibernate itself generate the database (even with the same dialect used in liquibase-hibernate) the constraint is generated and the user gets deleted when tenant is deleted. (confirmed by local unit test)

Do you have any advisory for this case other than adding the onDelete action by hand?

Regards
David

┆Issue is synchronized with this Jira Bug by Unito

@szczebel
Copy link

szczebel commented Jan 4, 2020

3 years without a resolution... any chance to get this fixed?

@dkunzler , did you figure out a workaround?

@dkunzler
Copy link
Author

dkunzler commented Jan 8, 2020

Hey, @szczebel as far as I remember I had at least seen some interesting behaviour about this one. I will have a look at this project and let you know what I've found out within the next few days!

@stefpiatek
Copy link

@dkunzler, imagine I'm dregding up the past I'd be keen if you did find anything for this.

@dkunzler
Copy link
Author

Hi @stefpiatek

sorry I forgot in january.

I created a gist with our code:
https://gist.github.com/dkunzler/d8bf1402cf2d5848b4c1e4fc29bffd94

strangely the two classes I added in the gist are not used or configured anywhere, I guess that they are picked up automatically by liquibase since they reside in the liquibase package.

With this code I was able to generate the onDelete action on foreign key constraints. However this will not pick up a deleted @OnDelete annotation, so just adding them.

Since this project is rather old the version used here is 'org.liquibase.ext:liquibase-hibernate5:3.6'

Perhaps that will help you. You can also comment on the gist if you have questions

@stefpiatek
Copy link

stefpiatek commented May 29, 2020

That's great, thanks for the gist, handy to see that it'll get picked up and adding it in isn't too much work.

Because it's an intentional decision not to include any FK properties, I wonder whether a PR to add in on delete functionality alone (say turned on in the liquibase.properties) would be accepted?

@stefpiatek
Copy link

In case others find it useful, here's our implementation and testing for generating changelogs with @onDelete that can be run as a maven goal https://github.com/inform-health-informatics/liquibase-hibernate-fk-on-delete

@filipelautert
Copy link
Collaborator

Hi" If this could be converted to a PR I can review and merge it... if there is still interest in this improvement ;)

@stefpiatek
Copy link

Ah yeah I've been putting this off as my changes have gotten stale. I'll see if I get some time set aside to update and make a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants