From b2bd587e6a92c5b328a92efc43ce5dcd6f4ea594 Mon Sep 17 00:00:00 2001 From: Manoj Lakshan <48247516+ManojLL@users.noreply.github.com> Date: Sun, 27 Oct 2024 01:00:26 +0530 Subject: [PATCH] TRUNK-5946: ProgramAttributeType Domain - Switching from Hibernate Mappings to Annotations (#4777) * TRUNK-5946: ProgramAttributeType Domain switching from XML Mappings to Annotations * TRUNK-5946: Updated OrderService test * TRUNK-5946: added ID generating sequence --- .../org/openmrs/ProgramAttributeType.java | 20 ++++++ api/src/main/resources/hibernate.cfg.xml | 1 - .../db/hibernate/ProgramAttributeType.hbm.xml | 63 ------------------- .../org/openmrs/api/OrderServiceTest.java | 2 + 4 files changed, 22 insertions(+), 64 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/ProgramAttributeType.hbm.xml diff --git a/api/src/main/java/org/openmrs/ProgramAttributeType.java b/api/src/main/java/org/openmrs/ProgramAttributeType.java index a2313c694f4d..fd5a49608ccb 100644 --- a/api/src/main/java/org/openmrs/ProgramAttributeType.java +++ b/api/src/main/java/org/openmrs/ProgramAttributeType.java @@ -10,12 +10,32 @@ package org.openmrs; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Parameter; import org.hibernate.envers.Audited; import org.openmrs.attribute.AttributeType; import org.openmrs.attribute.BaseAttributeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "program_attribute_type") @Audited public class ProgramAttributeType extends BaseAttributeType implements AttributeType { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "program_attribute_type_id_seq") + @GenericGenerator( + name = "program_attribute_type_id_seq", + strategy = "native", + parameters = @Parameter(name = "sequence", value = "program_attribute_type_program_attribute_type_id_seq") + ) + @Column(name = "program_attribute_type_id") private Integer programAttributeTypeId; @Override diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 8bcc951d75b0..05e1299293e4 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -81,7 +81,6 @@ - diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/ProgramAttributeType.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/ProgramAttributeType.hbm.xml deleted file mode 100644 index e85f1bb7a95c..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/ProgramAttributeType.hbm.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - program_attribute_type_program_attribute_type_id_seq - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/api/src/test/java/org/openmrs/api/OrderServiceTest.java b/api/src/test/java/org/openmrs/api/OrderServiceTest.java index c357f0d95101..60b6ad9516c8 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -56,6 +56,7 @@ import org.openmrs.PatientState; import org.openmrs.PersonAddress; import org.openmrs.PersonAttributeType; +import org.openmrs.ProgramAttributeType; import org.openmrs.Provider; import org.openmrs.ProviderAttributeType; import org.openmrs.Relationship; @@ -2736,6 +2737,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(DrugIngredient.class) .addAnnotatedClass(AlertRecipient.class) .addAnnotatedClass(PatientIdentifierType.class) + .addAnnotatedClass(ProgramAttributeType.class) .addAnnotatedClass(HL7InError.class) .getMetadataBuilder().build();