Hello,
I’m making a demo project where I’m using event sourcing - events are correctly stored in DomainEventEntry table.
However, I also need to get snapshots running and this is where i’m facing problems.
Snapshots get triggered, but in SnapshotEventEntry table, only the first (root) event is stored , a.k.a ‘…CreatedEvent’, even though the sequence number gets incremented.
Now when i put non-serializable variable to the Aggregate, like entity manager, the snapshotting fails on serialization, but in DB there is a payload with data about the event, although just the 2 events - ‘…CreatedEvent’ and ‘…ChangedEvent’ and sequence number is 1.
I think it might do something with transactions - i dont use Spring, so my transaction looks like this :
public class TransactionManager implements org.axonframework.common.transaction.TransactionManager{
@Override
public Transaction startTransaction() {
return new Transaction();
}
}
public class Transaction implements org.axonframework.common.transaction.Transaction {
final EntityManager entityManager;
public Transaction() {
this.entityManager = EntityManagerProvider.get();
if(entityManager.getTransaction().isActive()){
entityManager.getTransaction().commit();
}
entityManager.getTransaction().begin();
}
@Override
public void commit() {
entityManager.getTransaction().commit();
}
@Override
public void rollback() {
entityManager.getTransaction().rollback();
}
}