State-Stored Aggregates with id different from aggregate identifier

Hi all,

In case of a state-stored aggregate, is it possible to have the persistence id separate from the aggregate identifier?
What I try to achieve here is to use a sequence as the primary key and not the aggregate identifier, if possible.
It works for creating a new state but when I try to send a command that updates the state the command gateway throws an error.

For instance:

`
@Entity
@Aggregate
public class MyAggregate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long persistenceId;

@AggregateIdentifier
private MyValueObjectId myValueObjectId;


}
`

`
public class MyCommand {
@TargetAggregateIdentifier
public final MyValueObjectId myValueObjectId;


}
`

Error: Provided id of the wrong type … Expected: class java.lang.Long, got java.lang.String.

Kind regards,
Nick

Hi Nick,

You can definitely have a generated sequence in your Aggregate entity.
But I am pretty confident that Axon’s Repository expects the provided identifier to load the aggregate with to be the same as the identifier with which it is stored.
What you are essentially doing is segregating the field to load with from the field to store it with.
This somewhat breaks the definition of the Aggregate too, that it requires a "single external reference into the aggregate.

So, sadly, I don’t think this is an option Nick.
Then again, I haven’t tested this myself ever.
Maybe a more extended stack trace would give me a pointer to whether this definitely cannot be done(?).

Cheers,
Steven