Hi,
I’m trying to integrate Axon 2 on a JHipster POC project.
The code was working fine within a SpringBoot project and a JdbcEventRepositiory.
I moved everything inside the JHipster project and changed the JdbcEventReposity with a JpaEventRepository and now when I execute the statement
repository.load(command.getAggId());
I receive the error “AggregateIdentifier is unknown”.
More details are available below…
Any help will be appreciated.
Kind regards,
Giancarlo
`
2017-07-17 16:26:08.687 DEBUG 42541 — [ XNIO-2 task-2] o.a.unitofwork.NestableUnitOfWork : Registering Unit Of Work as CurrentUnitOfWork
2017-07-17 16:26:11.300 DEBUG 42541 — [ XNIO-2 task-2] org.hibernate.SQL : select snapshotev0_.event_identifier as col_0_0_, snapshotev0_.aggregate_identifier as col_1_0_, snapshotev0_.sequence_number as col_2_0_, snapshotev0_.time_stamp as col_3_0_, snapshotev0_.payload_type as col_4_0_, snapshotev0_.payload_revision as col_5_0_, snapshotev0_.payload as col_6_0_, snapshotev0_.meta_data as col_7_0_ from snapshot_event_entry snapshotev0_ where snapshotev0_.aggregate_identifier=? and snapshotev0_.type=? order by snapshotev0_.sequence_number DESC limit ?
Hibernate: select snapshotev0_.event_identifier as col_0_0_, snapshotev0_.aggregate_identifier as col_1_0_, snapshotev0_.sequence_number as col_2_0_, snapshotev0_.time_stamp as col_3_0_, snapshotev0_.payload_type as col_4_0_, snapshotev0_.payload_revision as col_5_0_, snapshotev0_.payload as col_6_0_, snapshotev0_.meta_data as col_7_0_ from snapshot_event_entry snapshotev0_ where snapshotev0_.aggregate_identifier=? and snapshotev0_.type=? order by snapshotev0_.sequence_number DESC limit ?
2017-07-17 16:26:11.306 DEBUG 42541 — [ XNIO-2 task-2] org.hibernate.SQL : select domaineven0_.event_identifier as col_0_0_, domaineven0_.aggregate_identifier as col_1_0_, domaineven0_.sequence_number as col_2_0_, domaineven0_.time_stamp as col_3_0_, domaineven0_.payload_type as col_4_0_, domaineven0_.payload_revision as col_5_0_, domaineven0_.payload as col_6_0_, domaineven0_.meta_data as col_7_0_ from domain_event_entry domaineven0_ where domaineven0_.aggregate_identifier=? and domaineven0_.type=? and domaineven0_.sequence_number>=? order by domaineven0_.sequence_number ASC limit ?
Hibernate: select domaineven0_.event_identifier as col_0_0_, domaineven0_.aggregate_identifier as col_1_0_, domaineven0_.sequence_number as col_2_0_, domaineven0_.time_stamp as col_3_0_, domaineven0_.payload_type as col_4_0_, domaineven0_.payload_revision as col_5_0_, domaineven0_.payload as col_6_0_, domaineven0_.meta_data as col_7_0_ from domain_event_entry domaineven0_ where domaineven0_.aggregate_identifier=? and domaineven0_.type=? and domaineven0_.sequence_number>=? order by domaineven0_.sequence_number ASC limit ?
2017-07-17 16:26:12.923 DEBUG 42541 — [ XNIO-2 task-2] o.a.repository.LockingRepository : Exception occurred while trying to load an aggregate. Releasing lock.
org.axonframework.domain.AggregateIdentifierNotInitializedException: AggregateIdentifier is unknown in […ao.lotto.LottoAO]. 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.AbstractRepository.load(AbstractRepository.java:86)
at org.axonframework.repository.AbstractRepository.load(AbstractRepository.java:39)
`
This is the Axon’s configuration:
`
@Configuration
@AnnotationDriven
@EntityScan(basePackageClasses = {Lotto.class, DomainEventEntry.class})
public class AxonConfiguration {
@Autowired
private EntityManager entityManager;
@Autowired
private DataSource dataSource;
@Autowired
private PlatformTransactionManager transactionManager;
@Bean
public Serializer serializer() {
return new JacksonSerializer();
}
@Bean
public EventBus eventBus() {
return new SimpleEventBus();
}
@Bean
public TransactionManager axonTransactionManager() {
return new SpringTransactionManager(transactionManager);
}
@Bean
public CommandBus commandBus() {
SimpleCommandBus commandBus = new SimpleCommandBus();
commandBus.setHandlerInterceptors(Arrays.asList(new BeanValidationInterceptor()));
commandBus.setTransactionManager(axonTransactionManager());
return commandBus;
}
@Bean
public EntityManagerProvider entityManagerProvider() {
return new SimpleEntityManagerProvider(entityManager);
}
@Bean
public EventStore eventStore() {
return new JpaEventStore(entityManagerProvider());
}
@Bean
public DefaultCommandGateway defaultCommandGateway() {
return new DefaultCommandGateway(commandBus());
}
@Bean
public Repository<LottoAO> lottoAORepository() {
EventSourcingRepository<LottoAO> repository = new EventSourcingRepository<>(LottoAO.class, eventStore());
repository.setEventBus(eventBus());
return repository;
}
@Bean
public Repository<SpedizioneAO> spedizioneAORepository() {
EventSourcingRepository<SpedizioneAO> repository = new EventSourcingRepository<>(SpedizioneAO.class, eventStore());
repository.setEventBus(eventBus());
return repository;
}
}
`
This is the relevant part of the aggregate:
`