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

CassandraMappingContext is adding to many persistent entities [DATACASS-745] #914

Closed
spring-projects-issues opened this issue Mar 23, 2020 · 4 comments
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Mar 23, 2020

Łukasz Świątek opened DATACASS-745 and commented

I might be wrong on this, but it looks like MappingCassandraContext will walk then entire object tree for initialEntrySet entities

this includes classes which will never be mapped directly

 

for example

@Table @Data
class Demo{
  @Id String id;
  @CassandraType(type = Name.TEXT)
  ComplexObject object;
}
 

Since object must be converted to text, i would assume there is no need to scan this class for persistent entities, it will always be mapped to/from text


No further details from DATACASS-745

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Mar 23, 2020

Mark Paluch commented

The mapping context is a meta-data collection about every seen type. Types are added as they are seen if they are not Java-library or driver types. Spring Data is lenient about type usage so you could also use types that are not annotated with @Table in queries. A typical use-case for types mapped to simple types are wrappers and embeddables that are supported in various other Spring Data modules (such as Spring Data JDBC).

That being said, that's expected behavior.

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Mar 24, 2020

Łukasz Świątek commented

Mark Paluch

but at the same time this behavior can cause problems which are not easy to solve

Given the example above, my ComplexObject will always be persisted as json. One of its nested fields is of type that cannot be registered as persistent entity because it has a field name starting with '_' . For object -> json i already have conversions sorted out, but there is no way to override spring data to ignore this type, it will just throw an exception and refuse to continue. This class is not part of the project and i cannot (or want to) add any annotations to "help" spring figure out how to handle it

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Mar 24, 2020

Mark Paluch commented

One of its nested fields is of type that cannot be registered as persistent entity because it has a field name starting with '_'

Can you provide a stack trace? Metadata scanning should not fail for plain classes

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Mar 25, 2020

Łukasz Świątek commented

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraMapping' defined in class path resource [com/example/demodata/CassConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: given string [_ent2] is not a valid quoted or unquoted identifier
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.resolveBeanReference(ConfigurationClassEnhancer.java:362)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:334)
	at com.example.demodata.CassConfig$$EnhancerBySpringCGLIB$$c35308a2.cassandraMapping(<generated>)
	at org.springframework.data.cassandra.config.AbstractCassandraConfiguration.cassandraConverter(AbstractCassandraConfiguration.java:128)
	at com.example.demodata.CassConfig$$EnhancerBySpringCGLIB$$c35308a2.CGLIB$cassandraConverter$10(<generated>)
	at com.example.demodata.CassConfig$$EnhancerBySpringCGLIB$$c35308a2$$FastClassBySpringCGLIB$$e7eb42b0.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at com.example.demodata.CassConfig$$EnhancerBySpringCGLIB$$c35308a2.cassandraConverter(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 107 more
Caused by: java.lang.IllegalArgumentException: given string [_ent2] is not a valid quoted or unquoted identifier
	at org.springframework.data.cassandra.core.cql.CqlIdentifier.<init>(CqlIdentifier.java:97)
	at org.springframework.data.cassandra.core.cql.CqlIdentifier.of(CqlIdentifier.java:138)
	at org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentProperty.createColumnName(BasicCassandraPersistentProperty.java:373)
	at org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentProperty.determineColumnName(BasicCassandraPersistentProperty.java:361)
	at org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentProperty.getColumnName(BasicCassandraPersistentProperty.java:134)
	at org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty.getRequiredColumnName(CassandraPersistentProperty.java:66)
	at org.springframework.data.cassandra.core.mapping.CassandraPersistentPropertyComparator.compare(CassandraPersistentPropertyComparator.java:95)
	at org.springframework.data.cassandra.core.mapping.CassandraPersistentPropertyComparator.compare(CassandraPersistentPropertyComparator.java:40)
	at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
	at java.base/java.util.TimSort.sort(TimSort.java:220)
	at java.base/java.util.Arrays.sort(Arrays.java:1515)
	at java.base/java.util.ArrayList.sort(ArrayList.java:1749)
	at org.springframework.data.mapping.model.BasicPersistentEntity.verify(BasicPersistentEntity.java:430)
	at org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity.verify(BasicCassandraPersistentEntity.java:157)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:377)
	at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.addPersistentEntity(CassandraMappingContext.java:308)
	at java.base/java.util.Collections$SingletonSet.forEach(Collections.java:4797)
	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:548)
	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:506)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:705)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:374)
	at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.addPersistentEntity(CassandraMappingContext.java:308)
	at java.base/java.util.Collections$SingletonSet.forEach(Collections.java:4797)
	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:548)
	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:506)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:705)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:374)
	at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.addPersistentEntity(CassandraMappingContext.java:308)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:323)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.data.mapping.context.AbstractMappingContext.initialize(AbstractMappingContext.java:452)
	at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.initialize(CassandraMappingContext.java:121)
	at org.springframework.data.mapping.context.AbstractMappingContext.afterPropertiesSet(AbstractMappingContext.java:444)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
	... 127 more
 

tables are

@Table
@Data
public class SimpleEntity {
    @Id String id;

    @CassandraType(type = DataType.Name.TEXT)
    ComplexObject complexObject;
}

@Data
class ComplexObject {
    String value1;
    NotPersistentEntity value2;
}

@Data
class NotPersistentEntity{
    String _ent1;
    String _ent2;
}
 

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement labels Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants