-
Notifications
You must be signed in to change notification settings - Fork 101
Recipe to remove Id annotation from Embeddable class when referenced by EmbeddedId #413
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
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.
Implementation looks perfect to me; great to see! I've done some very minor touch ups to the docs, code highlighting inside text blocks, and formatting. Good to merge if you ask me, but let's wait for @cjobinabo to return before we merge.
|
||
import static org.openrewrite.java.Assertions.java; | ||
|
||
class RemoveEmbeddableIdTest implements RewriteTest { |
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.
It would be good to include the following scenarios:
Class1
annotated with@Entity
and defines a field of typeClass2
annotated with@Embedded
. ThenClass2
's definition is annotated with@Embeddable
and defines a field of any type annotated with@Id
@Embeddable
is used on a sub-class where this sub-class uses@Id
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.
Does this recipe also have to handle the @Embedded
case? The rule only mentioned @EmbeddableId
.
Otherwise if you meant @EmbeddableId
, is the first case not the same as the first test, the one annotated with @DocumentExample
?
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.
In the second case, is Class1
still defining Class2
with @EmbeddableId
?
And should the recipe be expected to run on Subclass2
which extends Class2
?
import javax.persistence.Entity; | ||
@Entity | ||
public class MainEntity { |
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.
I should have been clearer about describing the sub-class test case I was looking for. Something like this was what I had in mind:
import javax.persistence.Embeddable;
import javax.persistence.Id;
public class SomeClass {
@Embeddable
public class EmbeddableObject {
@Id
private int field;
}
}
Without calling the super class you prevent the code the from branching any deeper.
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.
If SomeClass
also had it's own @Id
annotated field, should that be left unchanged by this recipe?
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.
Conversely, if the outer SomeClass
is @Embeddable
, has an @Id
field, and has an inner class without @Embeddable
and an inner field with @Id
, should that inner field annotation be removed as well?
Although not sure if this is easily feasible. Current behavior is to remove @Id
from current class and all inner classes from there.
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.
Thanks for making the updates
What's changed?
Add new recipe and tests for OpenJPA -> EclipseLink migration
Remove
@Id
annotation if...@Embeddable
and@EmbeddedId
What's your motivation?
https://wiki.eclipse.org/EclipseLink/Examples/JPA/Migration/OpenJPA/Mappings#.40EmbeddedId_and_.40Id_in_the_Same_Entity
Checklist