question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validate if the @AggregateIdentifier field implements toString() function

See original GitHub issue

When instantiating the meta-model of the aggregate, more specifically on retrieving the @AggregateIdentifier annotated field, we should verify that the annotated parameter implements a more precise toString() function than the default Object#toString() function.

This enforces users to some extent to ensure that the identifier they created returns a reasonable String version of their identifier.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
smcvbcommented, Jan 27, 2020

I would consider both to be fine, @vab2048. Axon is not biased to the exact format of the toString() result, as long as it isn’t the Object#toString() method which is being used. Using an UUID is definitely recommended; appending the type might be useful if you would want to reuse the UUID between distinct aggregate/entities.

So:

Does it matter which one is used?

No it does not, both would be fine.

0reactions
vab2048commented, Jan 27, 2020

I have come across this exception when testing my aggregates.

What exactly would constitute good practice for the implementation of toString?

Consider the following two:

  1. PortfolioId(id=bfb21d6e-7587-4dc4-8dbe-3ad4f3d758b5)
  2. bfb21d6e-7587-4dc4-8dbe-3ad4f3d758b5

The first is a default toString as would be implemented by lombok. The second a custom toString which just returns the id.

Does it matter which one is used?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to tell if an object implements a method like toString()?
The best I have found is by using java.lang.Class.getDeclaredMethod(String,Class<?>...) and calling it on the object's class hierarchy like ...
Read more >
Command Model - Axon Reference Guide
An Aggregate Root must declare a field that contains the Aggregate identifier. This identifier must be initialized at the latest when the first...
Read more >
A Guide to the Axon Framework - Baeldung
In this article, we'll be looking at Axon and how it helps us implement applications with CQRS (Command Query Responsibility Segregation) ...
Read more >
Event Sourcing with Spring Boot and Axon | Novatec
In this blog post I want to give an example on how to implement an event ... and contain a field with the...
Read more >
Spring Boot and Axon CQRS - LinkedIn
apply() method. 5. EventSourcing Handlers. The EventSourcing handler is a function that is called when an aggregate is sourced from its events.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found