Support for DB2 as database for DomainEventEntry and SnapshotEventEntry

Hi Allard,

Is it possible to use DB2 as database for the Axon tables?

Currently I’m getting the following exception:

org.springframework.beans.MethodInvocationException: Property ‘dataSource’ threw exception; nested exception is org.axonframework.common.AxonConfigurationException:The database product name ‘DB2/LINUXX8664’ is unknown. No SQLCode configuration is known for that database.

Thnx!

Onegini logo small signature[18].png

Hi Stein,

this exception is cause by the fact that Axon doesn’t recognize the String “DB2/LINUXX8664” as a known database. It uses the database name to detect which exceptions indicate an optimistic locking error.

There are two ways around this:

  1. disable the inspection. Simply remove the data-source property from the jpa-event-store, and you’re done.
  2. customize the persistence exception resolver. Remove the data-source property, and replace it with persitence-exception-resolver, lke so:

<axon:jpa-event-store persistence-exception-resolver=“persistenceExceptionResolver”/>


Since you’re using DB2, which is a known DB type, you can simply provide the database name as a constructor to the SQLErrorCodesResolver.

Hope this helps.
Cheers,

Allard

Onegini logo small signature[18].png

Hi Allard,

Thnx for the quick response once again! :slight_smile:

Onegini logo small signature[18].png

Hi Allard,

sorry for bringing this up again - but wouldn’t it be nice to support DB2 on Linux out of the box?
This is the version you are running when using the ibm docker image - so it should be quite usual.

For others as a quick workaround: Here is my Java-Config using Axon3 and DB2-LUW on Docker:

@Bean
public Serializer serializer() {

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    return new JacksonSerializer(objectMapper);
}

// An own resolver is needed because Axon doesn't recognize DB2 on linux correctly
@Bean
public SQLErrorCodesResolver sqlErrorCodesResolver() {
    return new SQLErrorCodesResolver("DB2");
}

@Bean
public EventStorageEngine eventStorageEngine(DataSource dataSource) throws SQLException {

    EntityManagerProvider entityManagerProvider = new SimpleEntityManagerProvider(entityManager);

    return new JpaEventStorageEngine(
        serializer(), NoOpEventUpcaster.INSTANCE, sqlErrorCodesResolver(),
        null, entityManagerProvider, NoTransactionManager.INSTANCE,
        null, null, true);
}

cu,
Dirk

Hi Dirk,

I have improved the SQL Error Codes mechanism to support patterns for database names. This should resolve the DB2 related issues.

Cheers,

Allard