org.axonframework.domain.AggregateIdentifierNotInitializedException: AggregateIdentifier is unknown in

Hey ,

I am new to axon and struggling with below error, any help is appreciated.

I am using jpa-event-store . The aggregate root is getting persisted in to device entry. The problem is when i try to load it from repo.

@Autowired

@Qualifier(“loginRepository”)

public void setRepository(Repository loginRepository) {

this.repository = loginRepository;

}

@CommandHandler

public void validateSession(ValidateSession command) {

AuthSession session = repository.load(command.getSessionId(), null);

session.validateSession(command.getSessionId());

}

2015-12-06 13:02:13,878 DEBUG svc:user org.axonframework.repository.LockingRepository#load:106 - Exception occurred while trying to load an aggregate. Releasing lock. [||||]

org.axonframework.domain.AggregateIdentifierNotInitializedException: AggregateIdentifier is unknown in [com.covisint.sso.aggregate.AuthSession]. Make sure the Aggregate Identifier is initialized before registering events.

at org.axonframework.domain.AbstractAggregateRoot.getEventContainer(AbstractAggregateRoot.java:174)

at org.axonframework.domain.AbstractAggregateRoot.initializeEventStream(AbstractAggregateRoot.java:145)

at org.axonframework.eventsourcing.AbstractEventSourcedAggregateRoot.initializeState(AbstractEventSourcedAggregateRoot.java:70)

at org.axonframework.eventsourcing.EventSourcingRepository.doLoad(EventSourcingRepository.java:177)

at org.axonframework.eventsourcing.EventSourcingRepository.doLoad(EventSourcingRepository.java:56)

at org.axonframework.repository.AbstractRepository.load(AbstractRepository.java:76)

at org.axonframework.repository.LockingRepository.load(LockingRepository.java:102)

at org.axonframework.repository.LockingRepository.load(LockingRepository.java:51)

at com.covisint.sso.handler.SessionCommandHandler.validateSession(SessionCommandHandler.java:70)

Hi,

make sure the field that is annotated with @AggregateIdentifier contains a non-null value after the first event has been applied/handled.
The first event from the event store should set this identifier on the aggregate

Cheers,

Allard

Thanks Allard. I can see that the aggregate is persisted in db. I created the ar on my first event. then i am invoking the validate with that identifier- trying to load it as you see in the validate session method below. Please help as it is a critical business requirement for us…

from db table-

4f67cdaf-0142-4678-aaa3-a704a5ccf162’, ‘0’, ‘AuthSession’, ‘24a13798-4492-4dd4-aca6-5f32f7d1f9bf’, NULL, ‘com.covisint.sso.api.CreateSessionRequestEvent’, ‘2015-12-06T12:55:44.418-05:00’, ?, ?

I am following the example from axon-trader where they simply load this object, where i get this exception. Can you please take a look again please.
I am trying to validate something here…

command-handler

@CommandHandler

public void createSession(CreateSession command) {

AuthSession session = new AuthSession(command.getSessionId(), command.getPasswordAct());

repository.add(session);

}

@CommandHandler

public void validateSession(ValidateSession command) {

AuthSession session = repository.load(command.getSessionId(), null); //This throws exception.

session.validateSession(command.getSessionId());

}

AggregateRoot

@AggregateIdentifier

private SessionId sessionId;

public AuthSession() {

}

public void setSessionId(SessionId sessionId) {

this.sessionId = sessionId;

}

public AuthSession(SessionId sessionId,PasswordAccount passwordAccount) {

this.sessionId = sessionId;

this.passwordAccount = passwordAccount;

apply(new CreateSessionRequestEvent(passwordAccount.getLoginId(),passwordAccount.getLoginId()));

logger.debug(" A new session request created with id - {} ", this.sessionId);

}

public boolean validateSession(SessionId sessionId) {

logger.debug(" Validate-session called - {} ", sessionId);

apply(new SessionValidatedEvent());

if (this.status == “ACTIVE”) {

return true;

} else {

return false;

}

}

Should this be an event sourced aggregate?
If so, there should be an @EventSourcingHandler to set the session ID to the value from the event.

Cheers,

Allard

ok, i got it.Thank you…

The sessionId was not set inside the @EventSourcingHandler instead it was set in the constructor.{I am forced to- before applying event.} , Now i set the sessionId both in constructor & @eventsourcinghandler. Now just one question, why is it forcing me to set the identifier before applying any event? I am taking about the first line in bold, in my constructor below?

public AuthSession(SessionId sessionId, Account account) {

this.sessionId = sessionId;

apply(new CreateSessionRequestEvent(this.sessionId, account));

}

The line in bold shouldn’t be necessary.

Cheers,

Allard