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

Warn when projectin DTO with id field using MongoDB #3260

Open
jurna opened this issue Dec 9, 2024 · 0 comments
Open

Warn when projectin DTO with id field using MongoDB #3260

jurna opened this issue Dec 9, 2024 · 0 comments
Assignees

Comments

@jurna
Copy link

jurna commented Dec 9, 2024

Expected Behavior

When mapping DTO projection, warning should not be logged (ant potentially no exception in internal code)

Actual Behaviour

When mapping DTO projection, warring is added to logs:
09:31:28.928 [Test worker] WARN i.m.d.m.o.AbstractMongoRepositoryOperations - Failed to map @Introspection annotated result. Now attempting to fallback and read object from the document. Error: Error instantiating type [com.example.customer.CustomerView] from introspection: Null argument specified for [id]. If this argument is allowed to be null annotate it with @Nullable

Looks like issue is here:

Steps To Reproduce

@Introspected
public record CustomerView(@BsonId @BsonRepresentation(OBJECT_ID) String id, String firstName, String lastName) {
}

@MappedEntity
@Data
@AllArgsConstructor
@NoArgsConstructor
public final class Customer {
    @Id
    @GeneratedValue
    private String id;
    private String firstName;
    private String lastName;

    private List<ChangeLog> changeLogs;
}
@MongoRepository
public interface CustomerRepository extends CrudRepository<Customer, String> {

    @MongoFindQuery(filter = "{}", project = "{ changeLogs: 0}")
    List<CustomerView> viewFindAll();
}

Environment Information

No response

Example Application

https://github.com/jurna/demo-micronaut/tree/customer_projection

Version

4.7.1

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

No branches or pull requests

2 participants