Skip to content

Commit

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

TRUNK-5671 Replace Provider hbm mapping file with annotations

TRUNK-5671 Replace Provider hbm mapping file with annotations

TRUNK-5671 Replace Provider hbm mapping file with annotations

TRUNK-5671 Replace Provider hbm mapping file with annotations
  • Loading branch information
wluyima authored and dkayiwa committed Nov 20, 2019
1 parent d77a3c4 commit 3a66cab
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 69 deletions.
56 changes: 56 additions & 0 deletions api/src/main/java/org/openmrs/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@
*/
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 @@ -17,20 +43,50 @@
*
* @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: 0 additions & 1 deletion api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
<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: 14 additions & 0 deletions api/src/main/resources/liquibase-update-to-2.3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,18 @@
<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>
</databaseChangeLog>

This file was deleted.

0 comments on commit 3a66cab

Please sign in to comment.