From a76e88d1d66993eb2bd299c2d9c17a9bf386ff1f Mon Sep 17 00:00:00 2001 From: ManojLL Date: Fri, 8 Nov 2024 14:48:23 +0530 Subject: [PATCH 1/3] TRUNK-5797: Migrate Field from Hibernate mapping XML to annotations --- api/src/main/java/org/openmrs/Field.java | 44 ++++++++-- api/src/main/resources/hibernate.cfg.xml | 1 - .../openmrs/api/db/hibernate/Field.hbm.xml | 85 ------------------- .../org/openmrs/api/OrderServiceTest.java | 1 + 4 files changed, 39 insertions(+), 92 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/Field.hbm.xml diff --git a/api/src/main/java/org/openmrs/Field.java b/api/src/main/java/org/openmrs/Field.java index d70496557745..486ce1ab40ff 100644 --- a/api/src/main/java/org/openmrs/Field.java +++ b/api/src/main/java/org/openmrs/Field.java @@ -13,34 +13,66 @@ import java.util.Set; import org.codehaus.jackson.annotate.JsonIgnore; +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.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + /** * Field * * @version 1.0 */ +@Entity +@Table(name = "field") @Audited public class Field extends BaseChangeableOpenmrsMetadata { public static final long serialVersionUID = 4454L; // Fields - + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "field_id_seq") + @GenericGenerator( + name = "field_id_seq", + strategy = "native", + parameters = @Parameter(name = "sequence", value = "field_field_id_seq") + ) + @Column(name = "field_id") private Integer fieldId; - + + @ManyToOne + @JoinColumn(name = "field_type") private FieldType fieldType; - + + @ManyToOne + @JoinColumn(name = "concept") private Concept concept; - + + @Column(name = "table_name", length = 50) private String tableName; + @Column(name = "attribute_name", length = 50) private String attributeName; - + + @Column(name = "default_value", columnDefinition = "TEXT") + @Lob private String defaultValue; - + + @Column(name = "select_multiple", length = 1, nullable = false) private Boolean selectMultiple = false; + @Transient private Set answers; // Constructors diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 2bd3c6ad8dc1..71d7335c6ac9 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -44,7 +44,6 @@ - diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/Field.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/Field.hbm.xml deleted file mode 100644 index 2be5c7bed175..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/Field.hbm.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - field_field_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..b28f74bd8565 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -2740,6 +2740,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(ProgramAttributeType.class) .addAnnotatedClass(HL7InError.class) .addAnnotatedClass(OrderType.class) + .addAnnotatedClass(Field.class) .getMetadataBuilder().build(); From 8582e0f0937f9acbc46bd4a135e7a26da9442985 Mon Sep 17 00:00:00 2001 From: ManojLL Date: Fri, 8 Nov 2024 15:08:42 +0530 Subject: [PATCH 2/3] TRUNK-5797: Migrate Field from Hibernate mapping XML to annotations --- api/src/main/java/org/openmrs/Field.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/Field.java b/api/src/main/java/org/openmrs/Field.java index 486ce1ab40ff..b225c675e89d 100644 --- a/api/src/main/java/org/openmrs/Field.java +++ b/api/src/main/java/org/openmrs/Field.java @@ -56,7 +56,7 @@ public class Field extends BaseChangeableOpenmrsMetadata { private FieldType fieldType; @ManyToOne - @JoinColumn(name = "concept") + @JoinColumn(name = "concept_id") private Concept concept; @Column(name = "table_name", length = 50) From 4c901c1a14782a5014d075cfa636ef77d2b703dc Mon Sep 17 00:00:00 2001 From: ManojLL Date: Sat, 9 Nov 2024 07:52:59 +0530 Subject: [PATCH 3/3] TRUNK-5797: Added annotated class to saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch test --- api/src/test/java/org/openmrs/api/OrderServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/org/openmrs/api/OrderServiceTest.java b/api/src/test/java/org/openmrs/api/OrderServiceTest.java index b28f74bd8565..a363187c2ff3 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -2740,7 +2740,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(ProgramAttributeType.class) .addAnnotatedClass(HL7InError.class) .addAnnotatedClass(OrderType.class) - .addAnnotatedClass(Field.class) + .addAnnotatedClass(org.openmrs.Field.class) .getMetadataBuilder().build();