Skip to content

Conversation

@sudhanshu-raj
Copy link
Contributor

@sudhanshu-raj sudhanshu-raj commented Nov 10, 2025

…notations

Description of what I changed

Issue I worked on

see https://openmrs.atlassian.net/browse/TRUNK-5866

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.

    No? -> execute above command

  • All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

@sudhanshu-raj sudhanshu-raj changed the title Trunk 5866 Trunk 5866 : OrderSet Domain - Switching from Hibernate Mappings to Annotations Nov 10, 2025
@sudhanshu-raj
Copy link
Contributor Author

Hey , I did the change , it should build success now .

@sudhanshu-raj
Copy link
Contributor Author

Hey @dkayiwa , can you please review this ?

@dkayiwa
Copy link
Member

dkayiwa commented Nov 11, 2025

Can you include a link to the ticket id as advised at https://openmrs.atlassian.net/wiki/display/docs/Pull+Request+Tips?

@sudhanshu-raj
Copy link
Contributor Author

Done !

private Operator operator;


@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you deal with the lazy attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think you can come up with a test in https://github.com/openmrs/openmrs-core/blob/master/api/src/test/java/org/openmrs/api/OrderSetServiceTest.java to catch this problem?

As in a test which would fail when using AttributeOverride but passes with AssociationOverride

}

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_set_id_seq")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of using GenerationType.IDENTITY?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In orderset.hbm.xml sequence has been used , so that's why not using identity here .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wikumChamith what is our recommended pattern for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just use IDENTITY as the strategy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5216 (comment)

Thanks , this is helpful

@sudhanshu-raj sudhanshu-raj force-pushed the TRUNK-5866 branch 2 times, most recently from 1a62eeb to c022deb Compare November 12, 2025 15:06
@Table(name = "order_set")
@Audited
@AssociationOverride(
name = "attributes",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this override for?

Copy link
Contributor Author

@sudhanshu-raj sudhanshu-raj Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overrides the join column name for attributes field ,actually in the OrderSet's parent class which is BaseCustomizableMetadata it has join column name location_id but in orderset.hbm.xml it has order_set_id join column name so it's overriding that join column name from it's parent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you evaluate using AttributeOverride?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttributeOverride works well for normal fields not for relationship attributes so here AssociationOverride will work for relationships columns like OneToMany

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when you are not modifying a relationship but just renaming a filed like here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes , this just renaming the column name , it's just can change how it should be mapped to databased like joincolumn name or jointable name , but can't actually modify the relationship like onetomany to manytoone , fetch type etc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't that then mean AttributeOverride is enough for this use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think @AttributeOverride works here. It’s used for simple attributes for example, renaming a column on a basic field like @Column(name = "idt") private String identifier; or for fields inside an @Embeddable. It only changes how a single column is named or mapped.

But for relationships like @OneToMany or @ManyToOne, we use @AssociationOverride. That’s what lets us change the name of the join column or join table for an existing relation.
This is what I understand, please let me know if I’m missing something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @AttributeOverride(name = "attributes", column = @column(name = "location_id")) annotation on the Location entity is not doing anything meaningful and can be safely removed. Why ? because :@AttributeOverride only works for simple fields (String, Integer, Date, etc.), not relationships like @onetomany

In BaseCustomizableMetadata, the attributes field is a relationship (@onetomany), not a basic column:

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@JoinColumn(name = "location_id")
private Set<A> attributes = new LinkedHashSet<>();

Since @AttributeOverride cannot override relationships, it gets silently ignored during entity mapping. The application runs fine without it which i also verified .

Ref : https://www.baeldung.com/jpa-attributeoverride
Recommendation: Remove the @AttributeOverride annotation from Location as it serves no purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants