-
Notifications
You must be signed in to change notification settings - Fork 4.1k
TRUNK-5950: RelationshipType Domain - Switching from Hibernate Mappings to Annotations #5570
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
…gs to Annotations
| */ | ||
| package org.openmrs; | ||
|
|
||
| import jakarta.persistence.*; |
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.
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 have fixed the wildcard imports (my IDE settings were overriding the style guide).
I also updated the PR to resolve the schema validation failure seen in the previous build. Fix: I used @AttributeOverride to map the inherited mandatory name field to the existing a_is_to_b column. I marked it as insertable=false, updatable=false so it acts as a read-only placeholder, which satisfies the validation check without conflicting with the actual data.
| @Id | ||
| @Column(name = "relationship_type_id") | ||
| @GeneratedValue(generator = "native") | ||
| @GenericGenerator(name = "native", strategy = "native", parameters = { |
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.
Let us just use Identity as done here: https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/Diagnosis.java#L56
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 the pointer! I've switched it to GenerationType.IDENTITY and confirmed that the tests still pass.
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.
You will also need to register the RelationshipType in the OrderServiceTest since its annotated now like here
https://github.com/openmrs/openmrs-core/pull/4531/files
| <mapping class="org.openmrs.ObsReferenceRange"/> | ||
| <mapping class="org.openmrs.ConceptReferenceRange"/> | ||
|
|
||
| <mapping class="org.openmrs.RelationshipType"/> |
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.
@shivvani-r Is this necessary,
Description of what I changed
I have migrated the
RelationshipTypedomain object from legacy Hibernate XML mappings to standard JPA annotations.Specific changes include:
@Entity,@Table,@Column) toRelationshipType.java.GenerationType.IDENTITYstrategy.@AttributeOverridewithinsertable = false, updatable = falseto map the inherited mandatorynamefield to the existinga_is_to_bcolumn (read-only). This resolves schema validation errors without requiring a database migration.RelationshipType.hbm.xmlfile.hibernate.cfg.xmlto reference the annotated class.Issue I worked on
see https://issues.openmrs.org/browse/TRUNK-5950
Checklist: I completed these to help reviewers :)
My IDE is configured to follow the code style of this project.
I have added tests to cover my changes. (Verified with PersonServiceTest)
I ran
mvn clean packageright before creating this pull request and added all formatting changes to my commit.All new and existing tests passed.
My pull request is based on the latest changes of the master branch.