Handling JPA annotations for BaseAttribute

Hi,

I’m writing API for one of our modules to manage Lab data. My model contains a class LabTest, which extends BaseCustomizableData<LabTestAttribute>

LabTestAttribute class further extends BaseAttribute<LabTestAttributeType, LabTest> and implements Attribute<LabTestAttributeType, LabTest> interface.

The module uses 2.x platform, so I’m using annotations and trying to avoid hibernate mappings in XML. I can see that properties in BaseOpenmrsMetadata and BaseOpenmrsData have been annotated. However, I don’t see any annotations for BaseAttribute and BaseCustomizableData; neither are these two annotated as @MappedSuperclass.

My question is why are these classes not annotated and how do I use them in my child classes without defining ORM in hibernate.hbm.xml?

It’s because historically we used xml, annotations were introduced in hibernate and JPA at a later point, so pretty much most persistent classes are mapped with xml and not annotations.

1 Like

Thanks @wyclif my assumption was that post 2.x, Openmrs got rid of all XML. So this would mean that I don’t have to worry about annotating any super classes…

We just added support for annotations but kept pretty much all the existing xml mappings

A little more on this @wyclif.

When making an entity attributable, the BaseAttribute abstract class can be extended to reproduce the functionality provided by location-location attributes; visit-visit attributes; provider-provider attributes…

The problem is that when extending this class, the implementer either has to fall back to hibernate 3.x style of XML mapping, or annotate the class (check this) and redefine properties of superclass, which is not OOP style and breaks inheritance rules.

Can we initialize the BaseAttribute class with @MappedSuperclass and annotate its properties? Not sure about the implications on the rest of the model, this may require modifications in mapping files of all attributable entities extending BaseAttribute class.

Of course BaseAttribute can be mapped with annotations just like BaseAttributeType but before this can be available in a future release, I find nothing wrong with using xml since it is still fully supported and I find it more flexible and robust.

1 Like

@wyclif Should I create a ticket for this then?

Ticket was created here https://issues.openmrs.org/browse/TRUNK-5402