Skip to content

Commit

Permalink
Revert "TRUNK-5671 Replace Provider hbm mapping file with annotations (
Browse files Browse the repository at this point in the history
…openmrs#3031)"

This reverts commit 3a66cab.
  • Loading branch information
wluyima committed Dec 19, 2019
1 parent 627ffbf commit 35fee6f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 70 deletions.
56 changes: 0 additions & 56 deletions api/src/main/java/org/openmrs/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,6 @@
*/
package org.openmrs;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.DiscriminatorOptions;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -43,50 +17,20 @@
*
* @since 1.9
*/
@Entity
@Table(name = "provider")
@DiscriminatorColumn(name = "provider_id", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorOptions(insert = false)
/*
* Provider inherits name and description properties from a superclass, name is optional but marked as required in a
* superclass so we need to override that. Description is not used but exists in a superclass and is marked as
* persistent, so hibernate generates a query containing the column which of course fails to execute because
* of the missing column, so we introduce this dummy table containing the column to 'please' hibernate.
*/
@SecondaryTable(name = "provider_unused_fields")
@AttributeOverrides({ @AttributeOverride(name = "name", column = @Column),
@AttributeOverride(name = "description", column = @Column(table = "provider_unused_fields", name = "description", insertable = false, updatable = false)) })
public class Provider extends BaseCustomizableMetadata<ProviderAttribute> {

private static final Logger log = LoggerFactory.getLogger(Provider.class);

@Id
@GeneratedValue
@Column(name = "provider_id")
private Integer providerId;

@ManyToOne
@JoinColumn(name = "person_id")
@Cascade(CascadeType.SAVE_UPDATE)
private Person person;

private String identifier;

@ManyToOne
@JoinColumn(name = "role_id")
private Concept role;

@ManyToOne
@JoinColumn(name = "speciality_id")
private Concept speciality;

@Access(AccessType.PROPERTY)
@OneToMany(mappedBy = "provider", cascade = javax.persistence.CascadeType.ALL, orphanRemoval = true)
@LazyCollection(LazyCollectionOption.TRUE)
@OrderBy("voided asc")
@BatchSize(size = 100)
private Set<ProviderAttribute> attributes = new LinkedHashSet<>();

public Provider() {
}

Expand Down
1 change: 1 addition & 0 deletions api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<mapping resource="org/openmrs/api/db/hibernate/VisitAttribute.hbm.xml" />

<!-- Provider -->
<mapping resource="org/openmrs/api/db/hibernate/Provider.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ProviderAttribute.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ProviderAttributeType.hbm.xml" />

Expand Down
14 changes: 0 additions & 14 deletions api/src/main/resources/liquibase-update-to-2.3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,6 @@
<column name="username" value="admin"/>
<where>system_id='admin'</where>
</update>
</changeSet>
<changeSet id="TRUNK-5671-20191017" author="Wyclif">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="provider_unused_fields" />
</not>
</preConditions>
<comment>Adding provider_unused_fields table</comment>
<createTable tableName="provider_unused_fields">
<column name="provider_id" type="int" >
<constraints nullable="false" unique="true" />
</column>
<column name="description" type="varchar(1)" />
</createTable>
</changeSet>
<changeSet id="20190815-Trunk-5650" author="gitacliff">
<preConditions onFail="MARK_RAN">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0"?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http:https://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
the terms of the Healthcare Disclaimer located at http:https://openmrs.org/license.
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
graphic logo is a trademark of OpenMRS Inc.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http:https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="org.openmrs">

<class name="Provider" table="provider">

<id name="providerId" type="java.lang.Integer" column="provider_id"
unsaved-value="0">
<generator class="native" />
</id>

<discriminator column="provider_id" insert="false" />

<many-to-one name="person" class="Person" column="person_id"
cascade="save-update" />

<property name="name" type="java.lang.String" length="255" access="field"/>

<property name="identifier" type="java.lang.String" length="255" />

<many-to-one name="creator" class="User" not-null="true" column="creator" />

<many-to-one name="role" class="Concept" column="role_id" />

<many-to-one name="speciality" class="Concept" column="speciality_id" />

<property name="dateCreated" type="java.util.Date" column="date_created"
not-null="true" length="19" />

<many-to-one name="changedBy" class="User" column="changed_by" />

<property name="dateChanged" type="java.util.Date" column="date_changed"
length="19" />

<many-to-one name="retiredBy" class="org.openmrs.User" column="retired_by" />

<property name="dateRetired" type="java.util.Date" column="date_retired" length="19" />

<property name="retireReason" type="java.lang.String" column="retire_reason" length="255" />

<property name="retired" type="boolean" length="1" not-null="true" />

<property name="uuid" type="java.lang.String" column="uuid" length="38" unique="true" />

<set name="attributes" lazy="true" inverse="true" batch-size="100"
cascade="all-delete-orphan" sort="unsorted" order-by="voided asc">
<key column="provider_id" />
<one-to-many class="ProviderAttribute" />
</set>


</class>

</hibernate-mapping>

0 comments on commit 35fee6f

Please sign in to comment.