Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CqlSessionFactoryBean implements PersistenceExceptionTranslator that leads to be instantiated by PersistenceExceptionTranslationInterceptor on every RuntimeException from a repository #1179

Open
vladtf opened this issue Oct 12, 2021 · 3 comments
Labels
type: enhancement A general enhancement

Comments

@vladtf
Copy link

vladtf commented Oct 12, 2021

org.springframework.data.cassandra.config.CqlSessionFactoryBean implements PersistenceExceptionTranslator that means that on each RuntimeException PersistenceExceptionTranslationInterceptor will find the bean for class CqlSessionFactoryBean to try translate the exception. If Cassandra is not available getBean method will fail with BeanCreationException because CqlSessionFactoryBean tried to connect to Cassandra and failed.

Expected behavior is that Spring will find a bean for class org.springframework.data.cassandra.core.cql.CassandraExceptionTranslator and try to translate RuntimeException using this bean, instead of trying to create a new object of CqlSessionFactoryBean.

A possible solution is to remove implements PersistenceExceptionTranslator from CqlSessionFactoryBean.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 12, 2021
@vladtf vladtf changed the title CqlSessionFactoryBean implements PersistenceExceptionTranslator that leads to be instantiated by SpringBoot CqlSessionFactoryBean implements PersistenceExceptionTranslator that leads to be instantiated by SpringBoot on every RuntimeException from a repository Oct 12, 2021
@vladtf vladtf changed the title CqlSessionFactoryBean implements PersistenceExceptionTranslator that leads to be instantiated by SpringBoot on every RuntimeException from a repository CqlSessionFactoryBean implements PersistenceExceptionTranslator that leads to be instantiated by PersistenceExceptionTranslationInterceptor on every RuntimeException from a repository Oct 12, 2021
@mp911de
Copy link
Member

mp911de commented Oct 13, 2021

This arrangement is in place since the inception of the Cassandra module. Using CqlSessionFactoryBean requires Cassandra connectivity and generally in Spring Data, exception translation is coupled to the factory bean that creates the client. Since Cassandra Driver 4, driver objects cannot be created any longer without Cassandra connectivity.

@vladtf
Copy link
Author

vladtf commented Oct 13, 2021

The thing is that I'm also using an ldap database. There is a flow when Cassandra is down, I search in ldap using spring repository, search fails because of no such object and it tries to translate ldap exception. When translating, it finds cassandra translator which is CqlSessionFactoryBean and when calling getBean of cqlSession it throws an BeanCreationException because it tried to connect to Cassandra.

@vladtf
Copy link
Author

vladtf commented Oct 13, 2021

As a workaround I added in jar an implementation that removes implementation of PersistenceExceptionTranslator from CqlSessionFactoryBean and registered a bean of class CassandraExceptionTranslator separately.

@schauder schauder added the type: enhancement A general enhancement label Oct 18, 2021
@schauder schauder added this to the 4.0 M1 (2022.1.0) milestone Oct 18, 2021
@schauder schauder removed the status: waiting-for-triage An issue we've not yet triaged label Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants