micronaut-data icon indicating copy to clipboard operation
micronaut-data copied to clipboard

JDBC: Column name has embedded id property name as prefix when using QueryModel directly

Open nhoughto opened this issue 3 years ago • 0 comments
trafficstars

Expected Behavior

An EmbeddedAssociation should not be included in the final SQL of a query, it is included because the foreign assocation comparison fails.

Actual Behaviour

The embedded association prefix is included because the NamingStrategy does an == comparison relying on object instance instead of and equals() comparison.

In default @NonNull String mappedName(@NonNull List<Association> associations, @NonNull PersistentProperty property) {

there is a condition to cover this case with the logic:

if (foreignAssociation != null) {
            if (foreignAssociation.getAssociatedEntity() == property.getOwner()
                    && foreignAssociation.getAssociatedEntity().getIdentity() == property) {
...

but when using QueryModel outside of the annotation processor the owner and the associated entity seem to have different instances, if this comparison was changed to an equals() or similar the problem wouldn't occur, an attempt at a fix is provided in the repro.

I realise i'm not meant to be using the QueryModel directly, but since there seems to be work underway via Criteria API to do just that, I thought it worth raising this as likely it would become a problem anyway?

Steps To Reproduce

  1. Repro here: https://github.com/nhoughto/micronaut-data-embeddedid
  2. Failing test: https://github.com/nhoughto/micronaut-data-embeddedid/blob/master/src/test/java/example/repositories/QueryTest.java
  3. Uncomment this for test to pass: https://github.com/nhoughto/micronaut-data-embeddedid/blob/master/src/main/java/example/domain/ActivityPeriodPersonId.java#L9

Environment Information

No response

Example Application

https://github.com/nhoughto/micronaut-data-embeddedid

Version

3.0.1, 3.2.0 of data

nhoughto avatar Nov 29 '21 22:11 nhoughto