Skip to content

Conversation

@shivvani-r
Copy link

@shivvani-r shivvani-r commented Dec 6, 2025

Description of what I changed

I have migrated the RelationshipType domain object from legacy Hibernate XML mappings to standard JPA annotations.

Specific changes include:

  • Added JPA annotations (@Entity, @Table, @Column) to RelationshipType.java.
  • Implemented the ID mapping using the standard GenerationType.IDENTITY strategy.
  • Used @AttributeOverride with insertable = false, updatable = false to map the inherited mandatory name field to the existing a_is_to_b column (read-only). This resolves schema validation errors without requiring a database migration.
  • Deleted the obsolete RelationshipType.hbm.xml file.
  • Updated hibernate.cfg.xml to 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 package right 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.

*/
package org.openmrs;

import jakarta.persistence.*;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

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.

@shivvani-r shivvani-r requested a review from dkayiwa December 7, 2025 04:49
@Id
@Column(name = "relationship_type_id")
@GeneratedValue(generator = "native")
@GenericGenerator(name = "native", strategy = "native", parameters = {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

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.

Copy link
Contributor

@suubi-joshua suubi-joshua left a 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"/>
Copy link
Contributor

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,

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

Successfully merging this pull request may close these issues.

3 participants