From 267c40002baf88361eda26a7ff38474926d17de0 Mon Sep 17 00:00:00 2001 From: ManojLL Date: Mon, 11 Nov 2024 10:01:41 +0530 Subject: [PATCH] TRUNK-5803: Migrate ConceptAnswer hibernate mapping from XML to annotations --- .../main/java/org/openmrs/ConceptAnswer.java | 38 +++++++++++++-- api/src/main/resources/hibernate.cfg.xml | 1 - .../api/db/hibernate/ConceptAnswer.hbm.xml | 47 ------------------- .../org/openmrs/api/OrderServiceTest.java | 2 + 4 files changed, 37 insertions(+), 51 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/ConceptAnswer.hbm.xml diff --git a/api/src/main/java/org/openmrs/ConceptAnswer.java b/api/src/main/java/org/openmrs/ConceptAnswer.java index 9a476af6e026..97f244ecb635 100644 --- a/api/src/main/java/org/openmrs/ConceptAnswer.java +++ b/api/src/main/java/org/openmrs/ConceptAnswer.java @@ -9,8 +9,19 @@ */ package org.openmrs; +import org.hibernate.annotations.BatchSize; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Parameter; import org.hibernate.envers.Audited; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; import java.util.Date; /** @@ -20,34 +31,55 @@ * * @see Concept#getAnswers() */ +@Entity +@Table(name = "concept_answer") +@BatchSize(size = 25) @Audited public class ConceptAnswer extends BaseOpenmrsObject implements Auditable, java.io.Serializable, Comparable { public static final long serialVersionUID = 3744L; // Fields + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "concept_answer_id_seq") + @GenericGenerator( + name = "concept_answer_id_seq", + strategy = "native", + parameters = @Parameter(name = "sequence", value = "concept_answer_concept_answer_id_seq") + ) + @Column(name = "concept_answer_id") private Integer conceptAnswerId; /** * The question concept that this object is answering */ + @ManyToOne + @JoinColumn(name = "concept_id", nullable = false) private Concept concept; /** * The answer to the question */ + @ManyToOne + @JoinColumn(name = "answer_concept", nullable = false) private Concept answerConcept; /** * The {@link Drug} answer to the question. This can be null if this does not represent a drug * type of answer */ + @ManyToOne + @JoinColumn(name = "answer_drug") private Drug answerDrug; - + + @ManyToOne + @JoinColumn(name = "creator", nullable = false) private User creator; - + + @Column(name = "date_created", nullable = false) private Date dateCreated; - + + @Column(name = "sort_weight") private Double sortWeight; // Constructors diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 2bd3c6ad8dc1..30335c2281ca 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -24,7 +24,6 @@ - diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/ConceptAnswer.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/ConceptAnswer.hbm.xml deleted file mode 100644 index 73f2e7d35f29..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/ConceptAnswer.hbm.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - concept_answer_concept_answer_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 6d553c038256..50d74f07c35d 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -22,6 +22,7 @@ import org.openmrs.Allergy; import org.openmrs.CareSetting; import org.openmrs.Concept; +import org.openmrs.ConceptAnswer; import org.openmrs.ConceptClass; import org.openmrs.ConceptDatatype; import org.openmrs.ConceptDescription; @@ -2740,6 +2741,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(ProgramAttributeType.class) .addAnnotatedClass(HL7InError.class) .addAnnotatedClass(OrderType.class) + .addAnnotatedClass(ConceptAnswer.class) .getMetadataBuilder().build();