Order.dateChanged, changedBy causing exception in ImmutableOrderInterceptor

Hello all :slight_smile:

while working on hibernate mapping through annotations for Order https://issues.openmrs.org/browse/TRUNK-4903

I got an

The following fields cannot be changed for class org.openmrs.Order:[changedBy, dateChanged]

org.openmrs.api.APIException: Editing some fields on Order is not allowed

in OrderEntryIntegrationTest and OrderServiceTest

it originates from

ImmutableOrderInterceptor

which prevents changes to fields which shouldnt change.

Now the funny part is the changedBy and dateChanged are not even persisted (not in db table orders).

My question should these two properties be added to the MUTABLE_PROPERTY_NAMES in the ImmutableOrderInterceptor ?

The orders table doesn’t have changed_by and date_changed columns, so you should not add annotations to those fields in the Java class just like the case in the hbm files

Order.java inherits those fields from https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/BaseOpenmrsData.java which has those annotations already.

If the annotations already exist on the superclass, then what is the point of TRUNK-4903?

As the issue says: its to move from hibernate mapping in XML to annotations

Please read the issue before answering. Thank you

First and foremost that ticket isn’t ready for work which in theory means work on it shouldn’t be underway. It also doesn’t say we get rid of XML.

Another thing to keep in mind is that historically we had avoided annotations because that makes the actual DAO implementation i.e hibernate creep into the API which is technically bad practice but we’re already doing it anyways and possibly inevitable. With that said, we finally agreed to introduce annotations since the JDK comes with an implementation of the JPA spec but it’s not as powerful/mature as hibernate, and the assumption was that we’re to use standard JPA annotations and only use hibernate ones where there is no JPA equivalent to minimize hibernate specific code in the API and this is why we really can’t get rid of XML configuration until the standard JPA has support for everything that we use in hibernate and my assumption is that it’s at that point that we can say we can get rid of XML

What’s that supposed to mean? There is a global ticket for moving away from xmls mappings to annotations. Not my invention

As long as jpa annotations are used their is no locking to hibernate. Which I assume hibernate xmls are. Anyway could you please stick to the issue and really read it. Thank you. I put some hours into it and also made code changes and tested them. Compiling openmrs core with my changes, deployed it and deployed the radiology module into openmrs.

just for the record: here is the ticket “Xml hibernate entities mappings should be replaced with annotations” https://issues.openmrs.org/browse/TRUNK-4666