Duplicate insert into DomainEventEntry

Have a weird issue where in dev within eclipse everything is fine with hsqldb…

however in prod with mySQL, I am getting

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘B56BF91E-4C6C-4A04-9688-0293970F9934-5-Deal’ for key ‘aggregateIdentifier’

The issue is that there are two commands being fired with futurecallbacks one after the other to aggregate commandhandler, however this works perfectly in dev vm in eclipse.

This is axon 1.x, in the bowels deep in Axon so am not sure whats gong on…am stuck… any ideas… Thanks and Cheers…

Hi,

there could be many things, but a wild guess would be that hsqldb uses isolation level “READ_COMMITTED”, while MySQL defaults to (I think) “REPEATABLE_READ”. Changing that to READ_COMMITTED might help. Did you try running against MySQL on your dev environment?

Since you are using future callbacks, I assume that you wait for the first command to be processed completely before sending the second? Is there any transaction surrounding these two operations, or do they run in their own transaction?

Hope this helps.

Cheers,

Allard

Should have been more detailed. also this is 1.2.1 Axon app… so here is the details

pojo class calls pojo service with 2 methods… and each method with future callback

service1.method1{
commandbus.dispatch(… ,futurecallback);
return;
}
service1.method2{
commandbus.dispatch(… .futurecallback);
return;
}
No explicit transaction manager…using axon integrated transaction manager and enitiyManager in spring config with executor.

Thats it. I think both these generate Domain events on same aggregate and the same sequence number is happening causing this problem… my Axon version for this app is 1.2.1… tried to upgrade to 1.4 for quick fix, however lot of stuff broke… maybe start seperate topic for that.

I have not run from eclipse jvm with mysql… will try and report if any issues.

This is feels like something inside Axon with threads… Let me know if I can provide stack traces etc directly to you.

Thanks and Cheers…

Hi,

I suppose you do futureCallback.getResult() (or just get() ) to wait for the result of the previous command?

I know there have been some changes since 1.2.1 in the locking mechanism used by Axon. However, I do not recall seeing this kind of problem ever before. What did you change that triggered this problem? Maybe that provides a lead as to where it comes from.

If you have some stack traces, you can send them to me directly. I’ll try to have a look at them.

Cheers,

Allard

Thanks Allard… you are genius…

Your suggestion for isolation level did the trick… This was a hairy one…Problem explanation and Solution below…

This problem occurs in scenario async command resulting in a command coming into same aggregate when it is still processing other commands and generating duplicate sequence for DomainEvententry

Need to configure IsolationLevelAdapter as a proxy to your real datasource.

Rename your existing datasource to something different… and then name the isolationAdapter to your original datasource referenced everywhere.

Thanks and Cheers…