-
Notifications
You must be signed in to change notification settings - Fork 4k
TRUNK-5861: Switch DrugIngredient domain from Hibernate mapping to annotations #5095
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
base: master
Are you sure you want to change the base?
Conversation
|
Hi @ibacher, |
|
Hi @ibacher, |
|
Hi@dkayiwa, |
| @Id | ||
| @MapsId("drugId") | ||
| @JoinColumn(name = "drug_id", nullable = false) | ||
| private Drug drug; |
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.
How are these changes related to the ticket?
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 — great question!
The change is part of the migration from Hibernate XML mapping to JPA annotations and doesn’t alter the model itself.
Explanation:
. drug_id and ingredient_id are a composite primary key (both were primaryKey="true" in the Liquibase snapshot).
. JPA doesn’t support having two separate @id annotations directly on @manytoone relations in a clean, maintainable way.
To represent the same composite key structure using annotations, we:
-
Introduced DrugIngredientId (@embeddable) to hold drugId and ingredientId.
-
Annotated the entity with @EmbeddedId private DrugIngredientId id.
-
Used @mapsid("drugId") and @mapsid("ingredientId") on the @manytoone relations so they map into the embedded ID fields — this mirrors the composite-id behavior from the old .hbm.xml.
In short:
Both drug_id and ingredient_id form a composite primary key, so we switched to using @EmbeddedId + @mapsid, which is the standard JPA approach for this case.
If you’d prefer the older style mapping, I can adjust accordingly.
Also, if you think it would help, I can add a one-line comment near the @mapsid annotations to make this intent clearer in the code.
|
Can you include a link to the ticket as advised at? https://openmrs.atlassian.net/wiki/display/docs/Pull+Request+Tips |
@dkayiwa, Thank you for the reminder. I’ve already included the link to the JIRA ticket in the PR description under the “Issue I worked on” section. |
|
Isn't this already done here? https://openmrs.atlassian.net/browse/TRUNK-6238 |
@dkayiwa , Yes i have checked and it's true it is already done but it remained open on jira board where i picked it from. Thank you for that clarification and reference! |
|
Sorry it looked like someone created a duplicate ticket. Do you mind closing it and the pull request? |
…a and its mapping tests
Description of what I changed
Issue I worked on
see https://issues.openmrs.org/browse/TRUNK-5861
Checklist: I completed these to help reviewers :)
[x ] My IDE is configured to follow the code style of this project.
No? Unsure? -> configure your IDE, format the code and add the changes with
git add . && git commit --amend[ x] I have added tests to cover my changes. (If you refactored
existing code that was well tested you do not have to add tests)
No? -> write tests and add them to this commit
git add . && git commit --amend[ x] I ran
mvn clean packageright before creating this pull request andadded all formatting changes to my commit.
No? -> execute above command
[ x] All new and existing tests passed.
No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.
[ x] My pull request is based on the latest changes of the master branch.
No? Unsure? -> execute command
git pull --rebase upstream master