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

Using lombok in combination with hypersistance optimizer #2364

Open
Docjones opened this issue Feb 12, 2020 · 2 comments
Open

Using lombok in combination with hypersistance optimizer #2364

Docjones opened this issue Feb 12, 2020 · 2 comments

Comments

@Docjones
Copy link

Docjones commented Feb 12, 2020

We are using Vlad Mihalceas Hypersistance Optimizer, a tool to check your data model for inconvenient usages.

One check is BidirectionalSynchronizationEvent, which is basically a check for Hibernates @OneToMany relationship and requests to add boilerplate code to keep the relationship on both sides in sync by adding

@OneToMany(mappedBy = "one")
private Set<MyDOM> many= new HashSet<>();

public void removeOne(MyDOM a) {
  many.remove(a);
  a.setOne(null);
}

public void addOne(MyDOM a) {
  many.add(a);
  a.setOne(this);
}

It would be nice to have a Lombok annotation for that.

@Maaartinus
Copy link
Contributor

I guess, you mean that starting with

@OneToMany(mappedBy = "one")
private Set<MyDOM> many= new HashSet<>();

both methods should be added. Lombok can't look at the other class, so it has to assume that in MyDOM the setter exists. I guess, that's OK.


Do you think that Lombok should do it, whenever it sees a field annotated with javax.persitence.OneToMany with a mappedBy field? Or only when an additional Lombok annotation is given?

@Docjones
Copy link
Author

Jup, that's what i meant.

Personally, i think it would be good to have a class-level annotation similar to @Setter or @Getter , that handles this specific persistence case.
I am sure, there are more cases like this, give the fact that hypersistance optimizer passes a few events around with (mild) suggestions regarding code quality/boilerplate.

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

No branches or pull requests

2 participants