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

Allow multiple keyspaces in one Spring context [DATACASS-290] #461

Closed
spring-projects-issues opened this issue May 23, 2016 · 5 comments
Closed
Assignees
Labels
in: core Issues in core support type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link

Cezary Kluczyński opened DATACASS-290 and commented

Currently there is no way of having entities mapped to tables in different keyspaces in a single Spring context. Is it something planned for future releases?

What's the recommended way of handling that kind of situation right now?


Referenced from: pull request #76

Backported to: 1.5 GA (Ingalls)

1 votes, 4 watchers

@spring-projects-issues
Copy link
Author

Mark Paluch commented

Using multiple keyspaces (various Session instances pointing to different keyspaces) is already possible. When using XML-based configuration, you need to leave the namespace support behind and declare beans using the factory beans (e.g. CassandraSessionFactoryBean).

It's not possible to use one Session with entities mapped to two different keyspaces. Specifying the keyspace in the table name leads to an exception:

@Table("keyspace.table")
public class MyEntity {…}

Your only solution is configuring the required infrastructure (Session, CassandraMappingContext, MappingCassandraConverter, CassandraOperations and repositories) for each keyspace you want to use.

@spring-projects-issues
Copy link
Author

Huge B commented

Getting the following error with multiple keyspaces:

found 2 beans of types [interface com.datastax.driver.core.Session,class org.springframework.data.cassandra.config.CassandraSessionFactoryBean] - can't disambiguate for creation of default [org.springframework.data.cassandra.core.CassandraTemplate]

Why doesn't the cassandra namespace support using multiple keyspaces? Seems like all it would have to do is not create the default CassandraTemplate instance if others are already defined

@spring-projects-issues
Copy link
Author

Mark Paluch commented

CassandraMappingBeanFactoryPostProcessor has a bug when checking for already registered bean names. It's possible to declare multiple CassandraTemplate beans but those are not taken into account when trying to create a default template bean

@spring-projects-issues
Copy link
Author

Mark Paluch commented

Switching this issue to Bug because the XML config allows specifying multiple beans with different Id's but the post-processor throws IllegalStateException

@spring-projects-issues
Copy link
Author

Ryan adams commented

I keep running into this issue when trying to use the SpringJUnit4ClassRunner. Not sure why, but it doesn't seem to have an issue when I instantiate the Spring beans via the ConfigurabeApplicationContext. Anyway, the fix seems rather easy:

Line 88 in the CassandraMapperBeanFactoryPostProcessor:

From this:
BeanDefinitionHolder[] templateBeans = getBeanDefinitionsOfType(registry, factory, CassandraOperations.class, true, false);
to this:
BeanDefinitionHolder[] templateBeans = getBeanDefinitionsOfType(registry, factory, CassandraTemplateFactoryBean.class, true, false);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants