Does Axon Framework integrate with hashicorp vault (hashicorp vault is where we save the database's encrypted username/password)

I am using postgres sql database and we are implementing the Saga orchestration using Axon Framework and axon server in my springboot based microservice. Our postgres db username and password are saved in hashicorp vault and our application data source reads them from the hashicorp vault. But I am not able to make the axon framework jar ( it’s data source) to read from the vault to ensure the database connections. In short story, how can I use the hashicorp vault when I am using axon framework jar, as axon framework jar will do CRUD operations in Saga related tables( like Saga_Entry, Token_entry etc. tables and will insert and read data from these tables).
Please help as I am stuck in it for past couple of days and not able to find any solution.

Hi @deepraj,

Axon uses the existing connection you have configured in your application. If you have a jpa connection configured it will use that.

-Ben

Hi @brunch ,
Thanks for your reply.

But in my case when I define the properties in application.properties file of my microservice, then we do not add username and password properties in application.properties file. These are read later (from a location/file which is created by hashicopr vault with database username and password as key value pair in it ) by the bean which initiate the data source. So when server is starting up then axon framework expects the username and password of the data base but it does not find it in application.properties then throws exception at startup of server.

Here is the java code for your reference…

Postgres DB Connection properties in application.properties file of springboot app

spring.datasource.url=jdbc:postgres://mypostgres.database.url:5432/mytestdb
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.properties.hibernate.default_schema=shoponline
spring.jpa.database-platform=org.hibernate.dialect.PostgresSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false

##Below is the JPA Data Source Configuration class which reads the database username and password from other vaulted property file and then creates the jpa datasource/transaction manager instance to be used later by repository classes

@Configuration
@EnableJpaRepositories(
basePackages = “com.my.app.repository”,
entityManagerFactoryRef = “emFactory”,
transactionManagerRef = “jpaTrnManager”
)
public class JPADataSourceConfiguration {
private static final Logger log = LogManager.getLogger(DataSourceConfiguration.class);

private Properties properties;

@Value("${spring.datasource.url}")
private String url;


@Bean(name = "postgresDBdatasource")
public HikariDataSource dataSource() {
	HikariDataSource dataSource = null;
	try {
		loadDBCredentialsFileToRead();
		dataSource = DataSourceBuilder
			.create()
			.url(url)
			.username((String) getDBUserName)
			.password((String) getDBPassword)
			.type(HikariDataSource.class)
			.build();
		dataSource.setPoolName("HikariPool");
	} catch (Exception e) {
		log.error("<<< Exception in setting datasource..  ", e);
	}
	return dataSource;
}


@Bean("emFactory")
public LocalContainerEntityManagerFactoryBean emFactory(EntityManagerFactoryBuilder builder) {
	return builder
		.dataSource(dataSource())
		.packages("com.my.app")
		.build();
}

@Bean(name = "jpaTrnManager")
public PlatformTransactionManager jpaTransactionManager(@Qualifier("emFactory") LocalContainerEntityManagerFactoryBean emf) {
	return new JpaTransactionManager(Objects.requireNonNull(emf.getObject()));
}

//Hashicorp vault stores the databse username and password in the file "pgdbcredentials.txt" (as key/value "dbusername", "dbpassword")at location "/db/credentials/file"
//The below method reads that file and the username and password later can be fectehd using Property class
private void loadDBCredentialsFileToRead(){
	properties = new Properties();
		InputStream io = null;
		try {
			io = new FileInputStream("/db/credentials/file/pgdbcredentials.txt");
			properties.load(io);				
			log.info("DB Username and password read successfully");
		} catch (FileNotFoundException e) {
			throw new RuntimeException("DB credentials file missing", e);
		}
	
}

public String getDBUserName() {
	return properties.getProperty("dbusername");
}

public String getDBPassword() {
	return properties.getProperty("dbpassword");
}

}

The below is my repository interface where I give reference of the “jpaTrnManager” bean to enable the jpa connection during CRUD operations…

@Repository
@Transactional(“jpaTrnManager”)
public interface OrderRepository extends JpaRepository<Order, Long>{

}

So my database username and password are read at run time from location(Not the application.properties of springboot app) which is having a file and then complete data source object is created. But the axon framework expects the username and password at the server startup time which I do not have at that time, and axon makes the start up of server fail…

Can you provide the error message you receive when it doesn’t start? My guess is that we need to include the following packages in your EntityManagerFactory…

org.axonframework.modelling.saga.repository.jpa, org.axonframework.eventhandling.tokenstore.jpa

-Ben

Hi @brunch,

Thanks for the help. Yes I included those packages too you mentioned. so it connects to database once and then starts throwing below exception… Please help as it has becomes complete show stopper for me…

2024-05-22 11:51:11.860 ERROR 1 — [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.context.ApplicationContextException: Failed to start bean ‘org.axonframework.spring.config.AxonConfiguration’; nested exception is org.axonframework.lifecycle.LifecycleHandlerInvocationException: One of the start handlers in phase [null] failed with the following exception:

at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.10.jar!/:5.3.10]

at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.10.jar!/:5.3.10]

at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.10.jar!/:5.3.10]

at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]

at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.10.jar!/:5.3.10]

at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.10.jar!/:5.3.10]

at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[spring-context-5.3.10.jar!/:5.3.10]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.10.jar!/:5.3.10]

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.5.jar!/:2.5.5]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.5.jar!/:2.5.5]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.5.jar!/:2.5.5]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.5.jar!/:2.5.5]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.5.jar!/:2.5.5]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.5.jar!/:2.5.5]

at com.freddiemac.fmos.FreddiemacSpringbootStarterApplication.main(FreddiemacSpringbootStarterApplication.java:10) ~[classes!/:0.1]

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]

at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]

at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[contractservice.jar:0.1]

at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[contractservice.jar:0.1]

at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[contractservice.jar:0.1]

at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[contractservice.jar:0.1]

Caused by: org.axonframework.lifecycle.LifecycleHandlerInvocationException: One of the start handlers in phase [null] failed with the following exception:

at org.axonframework.config.DefaultConfigurer.lambda$invokeStartHandlers$35(DefaultConfigurer.java:693) ~[axon-configuration-4.5.3.jar!/:4.5.3]

at org.axonframework.config.DefaultConfigurer.invokeLifecycleHandlers(DefaultConfigurer.java:744) ~[axon-configuration-4.5.3.jar!/:4.5.3]

at org.axonframework.config.DefaultConfigurer.invokeStartHandlers(DefaultConfigurer.java:687) ~[axon-configuration-4.5.3.jar!/:4.5.3]

at org.axonframework.config.DefaultConfigurer$ConfigurationImpl.start(DefaultConfigurer.java:811) ~[axon-configuration-4.5.3.jar!/:4.5.3]

at org.axonframework.spring.config.AxonConfiguration.start(AxonConfiguration.java:199) ~[axon-spring-4.5.3.jar!/:4.5.3]

at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.10.jar!/:5.3.10]

… 22 common frames omitted

Caused by: java.util.concurrent.ExecutionException: org.axonframework.lifecycle.LifecycleHandlerInvocationException: Failed during invocation of lifecycle handler [public void org.axonframework.axonserver.connector.processor.EventProcessorControlService.start()] on component [org.axonframework.axonserver.connector.processor.EventProcessorControlService@2eb1c615]

at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396) ~[na:na]

at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096) ~[na:na]

at org.axonframework.config.DefaultConfigurer.invokeLifecycleHandlers(DefaultConfigurer.java:742) ~[axon-configuration-4.5.3.jar!/:4.5.3]

… 26 common frames omitted

Caused by: org.axonframework.lifecycle.LifecycleHandlerInvocationException: Failed during invocation of lifecycle handler [public void org.axonframework.axonserver.connector.processor.EventProcessorControlService.start()] on component [org.axonframework.axonserver.connector.processor.EventProcessorControlService@2eb1c615]

at org.axonframework.config.LifecycleHandlerInspector.invokeAndReturn(LifecycleHandlerInspector.java:128) ~[axon-configuration-4.5.3.jar!/:4.5.3]

at org.axonframework.config.LifecycleHandlerInspector.lambda$null$0(LifecycleHandlerInspector.java:91) ~[axon-configuration-4.5.3.jar!/:4.5.3]

at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[na:na]

at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992) ~[na:na]

at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[na:na]

at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[na:na]

at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) ~[na:na]

at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]

at java.base/java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:662) ~[na:na]

at org.axonframework.config.DefaultConfigurer.invokeLifecycleHandlers(DefaultConfigurer.java:740) ~[axon-configuration-4.5.3.jar!/:4.5.3]

… 26 common frames omitted

Caused by: java.lang.reflect.InvocationTargetException: null

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]

at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]

at org.axonframework.config.LifecycleHandlerInspector.invokeAndReturn(LifecycleHandlerInspector.java:121) ~[axon-configuration-4.5.3.jar!/:4.5.3]

… 35 common frames omitted

Caused by: org.axonframework.eventhandling.tokenstore.UnableToRetrieveIdentifierException: Exception occurred while trying to establish storage identifier

at org.axonframework.eventhandling.tokenstore.jpa.JpaTokenStore.retrieveStorageIdentifier(JpaTokenStore.java:265) ~[axon-messaging-4.5.3.jar!/:4.5.3]

at org.axonframework.eventhandling.TrackingEventProcessor.lambda$calculateIdentifier$4(TrackingEventProcessor.java:245) ~[axon-messaging-4.5.3.jar!/:4.5.3]

at org.axonframework.common.transaction.TransactionManager.fetchInTransaction(TransactionManager.java:70) ~[axon-messaging-4.5.3.jar!/:4.5.3]

at org.axonframework.eventhandling.TrackingEventProcessor.calculateIdentifier(TrackingEventProcessor.java:244) ~[axon-messaging-4.5.3.jar!/:4.5.3]

at org.axonframework.eventhandling.TrackingEventProcessor.lambda$getTokenStoreIdentifier$3(TrackingEventProcessor.java:240) ~[axon-messaging-4.5.3.jar!/:4.5.3]

at java.base/java.util.concurrent.atomic.AtomicReference.updateAndGet(AtomicReference.java:210) ~[na:na]

at org.axonframework.eventhandling.TrackingEventProcessor.getTokenStoreIdentifier(TrackingEventProcessor.java:240) ~[axon-messaging-4.5.3.jar!/:4.5.3]

at org.axonframework.axonserver.connector.processor.StreamingEventProcessorInfoMessage.describe(StreamingEventProcessorInfoMessage.java:58) ~[axon-server-connector-4.5.3.jar!/:4.5.3]

at org.axonframework.axonserver.connector.processor.EventProcessorControlService.lambda$infoSupplier$1(EventProcessorControlService.java:115) ~[axon-server-connector-4.5.3.jar!/:4.5.3]

at io.axoniq.axonserver.connector.impl.ControlChannelImpl.lambda$sendScheduledProcessorInfo$3(ControlChannelImpl.java:245) ~[axonserver-connector-java-4.5.2.jar!/:4.5.2]

at java.base/java.util.concurrent.ConcurrentHashMap$ValuesView.forEach(ConcurrentHashMap.java:4780) ~[na:na]

at io.axoniq.axonserver.connector.impl.ControlChannelImpl.sendScheduledProcessorInfo(ControlChannelImpl.java:245) ~[axonserver-connector-java-4.5.2.jar!/:4.5.2]

at io.axoniq.axonserver.connector.impl.ControlChannelImpl.registerEventProcessor(ControlChannelImpl.java:226) ~[axonserver-connector-java-4.5.2.jar!/:4.5.2]

at org.axonframework.axonserver.connector.processor.EventProcessorControlService.lambda$start$0(EventProcessorControlService.java:105) ~[axon-server-connector-4.5.3.jar!/:4.5.3]

at java.base/java.util.HashMap.forEach(HashMap.java:1421) ~[na:na]

at org.axonframework.axonserver.connector.processor.EventProcessorControlService.start(EventProcessorControlService.java:103) ~[axon-server-connector-4.5.3.jar!/:4.5.3]

… 40 common frames omitted

Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Unable to access lob stream

at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:200) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3361) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3294) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]

at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]

at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:311) ~[spring-orm-5.3.10.jar!/:5.3.10]

at jdk.proxy2/jdk.proxy2.$Proxy118.find(Unknown Source) ~[na:na]

at org.axonframework.eventhandling.tokenstore.jpa.JpaTokenStore.getConfig(JpaTokenStore.java:272) ~[axon-messaging-4.5.3.jar!/:4.5.3]

at org.axonframework.eventhandling.tokenstore.jpa.JpaTokenStore.retrieveStorageIdentifier(JpaTokenStore.java:263) ~[axon-messaging-4.5.3.jar!/:4.5.3]

… 55 common frames omitted

Caused by: org.hibernate.HibernateException: Unable to access lob stream

at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.wrap(PrimitiveByteArrayTypeDescriptor.java:123) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.wrap(PrimitiveByteArrayTypeDescriptor.java:26) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$1.doExtract(BlobTypeDescriptor.java:48) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:243) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:329) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:3131) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.loadFromResultSet(EntityReferenceInitializerImpl.java:342) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.hydrateEntityState(EntityReferenceInitializerImpl.java:269) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:102) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails$EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:288) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractRows(ResultSetProcessorImpl.java:157) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:94) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:105) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:285) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.persister.entity.AbstractEntityPersister.doLoad(AbstractEntityPersister.java:4437) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4427) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:576) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:544) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:208) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:332) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:108) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:74) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:110) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1186) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1175) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.SessionImpl.access$2100(SessionImpl.java:193) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2779) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.lambda$load$1(SessionImpl.java:2767) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.perform(SessionImpl.java:2723) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2767) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3322) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

… 64 common frames omitted

Caused by: org.postgresql.util.PSQLException: ERROR: permission denied for large object 20597

at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2552) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.postgresql.core.v3.QueryExecutorImpl.receiveFastpathResult(QueryExecutorImpl.java:817) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.postgresql.core.v3.QueryExecutorImpl.fastpathCall(QueryExecutorImpl.java:604) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.postgresql.fastpath.Fastpath.fastpath(Fastpath.java:110) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.postgresql.fastpath.Fastpath.fastpath(Fastpath.java:152) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.postgresql.fastpath.Fastpath.getInteger(Fastpath.java:164) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.postgresql.largeobject.LargeObject.(LargeObject.java:107) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.postgresql.largeobject.LargeObjectManager.open(LargeObjectManager.java:246) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.postgresql.largeobject.LargeObjectManager.open(LargeObjectManager.java:229) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.postgresql.jdbc.AbstractBlobClob.getLo(AbstractBlobClob.java:272) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.postgresql.jdbc.AbstractBlobClob.getBinaryStream(AbstractBlobClob.java:117) ~[postgresql-42.2.23.jar!/:42.2.23]

at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.wrap(PrimitiveByteArrayTypeDescriptor.java:120) ~[hibernate-core-5.4.32.Final.jar!/:5.4.32.Final]

… 97 common frames omitted

Scrolling through your stack trace it appears that there is the PSQLException about permission denied for large object. I think this might be the cause of your problem.

yes but it was working fine when I deployed the application microservice first time. Again I simply the redeployed my application microservice as my axon server’s url had changed. So after that the application logs started off showing this exception and pod is not coming up because of this exception now. There was no other change then axon server ip address.

I am not using any kind fo new data objects also. They are pretty simple and small. my application has ononly 1 table with 4 columns in it. 3 varchar type column and 1 integer type column in the table.

So the tables that Axon Framework is creating have fields on them that qualify as large objects. Now you are creating those and then starting an Event Processor which needs access to the tokenentry table which has the column token on it. This is considered a large column.

ok @brunch . and how can I fix it then ?

FYI… I am creating the axon framework related tables in my postgres database schema using the flyway.
Below ones are by scripts to create those 3 tables…
CREATE TABLE IF NOT EXISTS shoponline.associationvalueentry
(
id bigint NOT NULL,
association_key character varying(255) NOT NULL,
association_value character varying(255),
saga_id character varying(255) NOT NULL,
saga_type character varying(255),
CONSTRAINT associationvalueentry1 PRIMARY KEY (id)
)

CREATE TABLE IF NOT EXISTS shoponline.sagaentry
(
saga_id character varying(255) NOT NULL,
revision character varying(255),
saga_type character varying(255),
serialized_saga oid,
CONSTRAINT sagaentry_pkey PRIMARY KEY (saga_id)
)

CREATE TABLE IF NOT EXISTS shoponline.tokenentry
(
processorname character varying(255) NOT NULL,
segment integer NOT NULL,
owner character varying(255),
timestamp character varying(255) NOT NULL,
token oid,
tokentype character varying(255),
CONSTRAINT tokenentry_pkey PRIMARY KEY (processorname, segment)
)

and below is my jpa configuration class which I modified as per my need…

@Configuration
public class JPADataSourceConfiguration {
private static final Logger log = LogManager.getLogger(DataSourceConfiguration.class);

private Properties properties;

@Value(“${spring.datasource.url}”)
private String url;

@Bean(name = “postgresDBdatasource”)
public HikariDataSource dataSource() {
HikariDataSource dataSource = null;
try {
loadDBCredentialsFileToRead();
dataSource = DataSourceBuilder
.create()
.url(url)
.username((String) getDBUserName)
.password((String) getDBPassword)
.type(HikariDataSource.class)
.build();
dataSource.setPoolName(“HikariPool”);
} catch (Exception e) {
log.error("<<< Exception in setting datasource… ", e);
}
return dataSource;
}

public void configureMySaga(EventProcessingConfigurer eventProcessingConfigurer,
@Qualifier(“axonEntityManagerProvider”) EntityManagerProvider entityManagerProvider) {
eventProcessingConfigurer.registerSaga(LoanProcessingSaga.class, sagaConfigurer → sagaConfigurer
.configureSagaStore(c → JpaSagaStore.builder()
.entityManagerProvider(entityManagerProvider).build()));
}
@Bean(“entityManagerFactory”)
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
return builder
.dataSource(dataSource())
.packages(“com.my.app.repository”
,“org.axonframework.eventhandling.tokenstore”
,“org.axonframework.modelling.saga.repository.jpa”
,“org.axonframework.eventsourcing.eventstore.jpa”)
.build();
}

 @Bean(name = "axonEntityManagerProvider")
    public EntityManagerProvider axonEntityManagerProvider(
    		@Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
        ContainerManagedEntityManagerProvider containerManagedEntityManagerProvider = new ContainerManagedEntityManagerProvider();
        containerManagedEntityManagerProvider.setEntityManager(entityManagerFactory.createEntityManager());
        return containerManagedEntityManagerProvider;
}

//Hashicorp vault stores the databse username and password in the file “pgdbcredentials.txt” (as key/value “dbusername”, “dbpassword”)at location “/db/credentials/file”
//The below method reads that file and the username and password later can be fectehd using Property class
private void loadDBCredentialsFileToRead(){
properties = new Properties();
InputStream io = null;
try {
io = new FileInputStream(“/db/credentials/file/pgdbcredentials.txt”);
properties.load(io);
log.info(“DB Username and password read successfully”);
} catch (FileNotFoundException e) {
throw new RuntimeException(“DB credentials file missing”, e);
}

}

public String getDBUserName() {
return properties.getProperty(“dbusername”);
}

public String getDBPassword() {
return properties.getProperty(“dbpassword”);
}

}

Hi @brunch ,

So can we change the type of column token (of table tokenentry) from oid to something else to fix this error?

You can try to avoid the whole large object issue by changing the data type of the columns that are oid…

Axon Framework and PostgreSQL without TOAST (axoniq.io)

1 Like

Hi @brunch,

Thanks so much It worked finally. I really appreciate your timely help Ben.