Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrade Micronaut version can't compile project - unable to implement Repository method for projection Entity with embedded ID #2705

Closed
alapierre opened this issue Dec 27, 2023 · 7 comments · Fixed by #2794
Assignees
Labels
type: bug Something isn't working

Comments

@alapierre
Copy link

alapierre commented Dec 27, 2023

Expected Behavior

project should compile and runs like in MN 4.1.3

Actual Behaviour

I upgraded Micronaut from 4.1.3 to 4.2.2 and my project stop compile with error:

Unable to implement Repository method: InvoiceRepository.findByTimestampBetween(OffsetDateTime from,OffsetDateTime to,Pageable pageable). Cannot apply a column alias: id with expanded property: io.micronaut.data.model.PersistentAssociationPath@64918740

method looks like that:

Page<SalesInvoiceShortDto> findByTimestampBetween(OffsetDateTime from, OffsetDateTime to, Pageable pageable);

and it use projections from Entity class to DTO. Entity has composite EmbeddedId key InvoiceId

@Data
@Embeddable
@Builder
public class InvoiceId implements Serializable {

    @Size(max = 256)
    @NotEmpty
    private String number;

    @Size(max = 15)
    @NotEmpty
    private String nip;

    @Tolerate
    public InvoiceId() {
    }
}

SalesInvoiceShortDto

@Introspected
@Value
public class SalesInvoiceShortDto {

    InvoiceId id;

    OffsetDateTime timestamp;

    OffsetDateTime lastUpdated;

    ProcessingStatusEnum processingStatus;

    String invoiceReferenceNumber;

    @Nullable
    String ksefNumber;

    @Nullable
    OffsetDateTime acquisitionTimestamp;

    @Nullable
    String buyerIdentifier;

    @Nullable
    String buyerName;

Invoice

@Entity
@Data
@Builder
@DynamicUpdate
class Invoice implements Serializable {

    @Tolerate
    public Invoice() {
    }

    @EmbeddedId
    private InvoiceId id;

...

When I remove InvoiceId id property from SalesInvoiceShortDto it works - but it is not what I want to do...

Steps To Reproduce

No response

Environment Information

JDK 17

Example Application

No response

Version

4.2.2

@radovanradic
Copy link
Contributor

Looks like introduced here #2495 with DTO association support

@radovanradic
Copy link
Contributor

@alapierre Can you please submit simple app that reproduces the error?
I have tried to reconstruct the app from the classes you pasted
mn-data-dto-projection.zip
but I am not getting compiler error. Apparently it is missing something, so please take a look and if possible reupload app that reproduces the error. Thanks

@alapierre
Copy link
Author

alapierre commented Jan 19, 2024

yes, sure. I will prepare demo app for you.

@radovanradic
Copy link
Contributor

Ok, I was able to reproduce. It happens with @Repository and not with @JdbcRepository it seems.

@alapierre
Copy link
Author

alapierre commented Feb 14, 2024

after upgrading to Micronaut to 4.3.1 I've got the same error. You do not need the sample project, do you?

The workaround is to use old fason new operator in a query, eg:

@Query("SELECT new io.alapierre.integrator.dto.InvoiceIdocId(i.id, i.idocId) FROM Invoice i WHERE i.sessionId = :sessionId AND i.id.tenant = :tenant")
List<InvoiceIdocId> findBySessionIdAndIdTenant(String sessionId, String tenant);

@radovanradic
Copy link
Contributor

I was able to reproduce, thanks. Maybe the solution would be to use new (..) constructor in query but it's not the best because it would force DTOs to have all params constructor etc.

@alapierre
Copy link
Author

yes, workaround is only to solve problem now. Let me know if I can help with that in any way. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants