GSoC-2020: Switching from XML Mappings to Annotations on OpenMRS domain Objects

Hi everyone! As the coding period is beginning soon, I create this public thread for my GSoC project to let you know about how is it going. The goal of this project is to switch from XML Mappings to Annotations on OpenMRS domain Objects. In the last days I documented a lot about this subject, and started switching with the class Drug. There is also created a big issue for this project(https://issues.openmrs.org/browse/TRUNK-5748) and by the time I will add more, related to this. I will do a list with all classes that need this change, and that will be the order. If you have any suggestions, ping me:). The project mentors are @ruhanga and @k.joseph . Hope for a great work by the end of GSoC!

1 Like

Hi @ruhanga ! How should look this into java annotations?

@alinmihaila99, have you googled a little?

One good site to checkout is;

1 Like

@alinmihaila99, could you also share the list of *.hbm.xml files you will be replacing?

Yes, sure. This is the document I will update whit the status of each class. The first two classes are in progress at this time.

Thanks. Could you arrange them in a google sheet instead?

2 Likes

Yes. Here is the link. And one more question. For testing should I disconnect the hbm from the project? And how to do this?

Yes for sure. You may also write some liquibase-change-sets to create the table(s) for production installations in liquibase-update-to-latest-2.4.x.xml if the respective table schemas were not introduced in earlier schema change sets like liquibase-schema-only-2.3.x.xml.

Here is an example of how it was done with the User domain. Note that this was latter reverted because of some little inconsistencies. These will be addressed as well.

Example;

@dkayiwa, @ibacher, @wolf, hope the above procedure is consistent with the liquibase changes that were introduced of late to optimise the installation process.

@wolf wrote this guide on working with Liquibase changes in the new model. I would hope that we wouldnā€™t need to introduce dummy tables like that though. I think what Wycliff was trying to do there couldā€™ve been better achieved by doing something like:

@Transient
@Override
public String getName() {
    return super.getName();
}

Although that may not have been possible for reasons Iā€™m ignorant of.

1 Like

Thanks @ibacher, this makes sense. I guess most, if not all entities/domains have their corresponding change-sets already. However referring to a worst case where the schema had to be changed, Iā€™d think we might have to introduce some schema updates?

Itā€™s certainly entirely possible that we will need some schema updates! I just hope we donā€™t need to end up with tables that are there to make Hibernate happy.

1 Like

Hi @ruhanga, @ibacher! In a case like this:

set name=ā€œconceptMappingsā€ inverse=ā€œtrueā€ cascade=ā€œall,delete-orphan,evictā€ batch-size=ā€œ25ā€

I read here that CascadeType.ALL substitute all other attributes. Should I include types EVICT and DELETE_ORPHAN? I know these types are deprecated and I found their substitute.

@alinmihaila99 i see no problem in adopting the new type substitutes unless its backwards incompatible :slightly_smiling_face:

Thanks @gcliff. @alinmihaila99 we always want to avoid deprecated method/constants. This way we will avoid inconsistencies that may arise by depending on such. Feel free to go ahead and do not hesitate trying/testing out as much as you can.

2 Likes

Hi @ruhanga @gcliff ! I have a problem with class Concept. I have been stuck with it 3 days and I really donā€™t know what to do. I added annotations for each field, but i have the following error. I think it is because Concept is extended by 2 other classes(ConceptNumeric and ConceptComplex), and that 2 classes dont have mappings, it is contained in Concept mapping with joined-subclass. I found something on google, but i think I miss something. Here is the link. If you have any ideas, please ping me

@alinmihaila99 i see NULL not allowed for column "DTYPE" this in the error logs ,

make the hibernate annotation mappings for the datatype columns in your concept table as its done in the the respective hibernate xml file

@alinmihaila99, do you have a PR for this, at least a draft PR? This will help assisting you easier. Also try to share the whole error logs using pastebin.com.

I did it but it doesenā€™t work. I will a draft PR to see exactly what I mean

Hi! I created a draft PR for Concept domain. The link is here: https://github.com/openmrs/openmrs-core/pull/3263/files. Any help would be very helpful. Thanks!

added a comment on your pr