Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion api/src/main/java/org/openmrs/RelationshipType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
*/
package org.openmrs;

import jakarta.persistence.AttributeOverride;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.envers.Audited;

Expand All @@ -33,21 +40,37 @@
* In English, we run into a tricky RelationshipType with aunts and uncles. We have chosen to define
* them as aunt/uncle-niece/nephew.
*/
@Entity
@Table(name = "relationship_type")
@Audited
/**
* The 'name' property is inherited from BaseChangeableOpenmrsMetadata, but the
* relationship_type table does not have a 'name' column. It uses 'a_is_to_b'
* and 'b_is_to_a' instead.
* * We map 'name' to 'a_is_to_b' (read-only) to satisfy the Hibernate requirement
* for the inherited field without breaking the legacy schema.
*/
@AttributeOverride(name = "name", column = @Column(name = "a_is_to_b", length = 50, insertable = false, updatable = false))
public class RelationshipType extends BaseChangeableOpenmrsMetadata{

public static final long serialVersionUID = 4223L;

// Fields

@Id
@Column(name = "relationship_type_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer relationshipTypeId;

@Column(name = "a_is_to_b", nullable = false, length = 50)
private String aIsToB;

@Column (name = "b_is_to_a", nullable = false, length = 50)
private String bIsToA;

@Column (nullable = false)
private Integer weight = 0;

@Column (nullable = false)
private Boolean preferred = false;

// Constructors
Expand Down
3 changes: 2 additions & 1 deletion api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<mapping resource="org/openmrs/api/db/hibernate/Role.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Patient.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/PatientProgramAttribute.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/RelationshipType.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Order.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/OrderAttribute.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/OrderAttributeType.hbm.xml" />
Expand Down Expand Up @@ -75,6 +74,8 @@
<!-- These mappings are required because of references in Obs & Concept -->
<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,

</session-factory>

</hibernate-configuration>

This file was deleted.