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

Use JoinColumn annotation for relationship mappings #416

Merged
merged 15 commits into from
Apr 23, 2024

Conversation

evie-lau
Copy link
Contributor

What's changed?

OpenJPA -> EclipseLink migration recipe
When a @Column annotated attribute has a relationship mapping (@OneToOne or @ManyToOne), replace with @JoinColumn and drop certain annotation attributes.

What's your motivation?

https://wiki.eclipse.org/EclipseLink/Examples/JPA/Migration/OpenJPA/Mappings#.40Column_in_Relationship_Mappings

Anything in particular you'd like reviewers to focus on?

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@evie-lau
Copy link
Contributor Author

evie-lau commented Feb 15, 2024

I noticed the doAfterVisit is applying changes to the whole file instead of the filtered VariableDeclaration.
Is there a way to apply those other recipes specifically to the current item? Or would I have to build my own JavaTemplate for it?
Modified recipe to only change the affected VariableDeclaration.

@evie-lau evie-lau self-assigned this Feb 16, 2024
@evie-lau evie-lau marked this pull request as ready for review February 16, 2024 20:21
@timtebeek timtebeek self-requested a review February 16, 2024 20:26
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Near perfect; Great to see you reuse as much as possible. We'll wait for @cjobinabo to return before a merge.

@timtebeek timtebeek requested a review from cjobinabo February 19, 2024 10:35
@timtebeek timtebeek added the recipe Recipe requested label Feb 19, 2024

import static org.openrewrite.java.Assertions.java;

class UseJoinColumnForMappingTest implements RewriteTest {
Copy link
Contributor

@cjobinabo cjobinabo Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following these cases should be ported over from our bucket:

We should also test the use of these annotations within a sub class here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean subclass extending the @Entity class? or an inner class inside the @Entity class?

Copy link
Contributor

@cjobinabo cjobinabo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@timtebeek timtebeek merged commit f1d17f5 into openrewrite:main Apr 23, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants