Closed apescione closed 4 years ago
@apescione these are the cosmosdb limits for item creation : https://docs.microsoft.com/en-us/azure/cosmos-db/concepts-limits#per-item-limits I think we should be able to support Long types as well, I am considering this feature for next semester.
Also, as an update, this repo is now being moved to azure-sdk-for-java : https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/cosmos/azure-spring-data-cosmosdb So going forward, all the issues should be created there. The repo movement is not yet complete and currently in progress.. Once it is completely moved, I will post an update on this repo.
Also, as a bigger ask, we are tracking this issue here as well : https://github.com/microsoft/spring-data-cosmosdb/issues/295
@apescione may I ask what happens when you use @Id
annotation on Long
type ?
Hi @kushagraThapar, thank you for replying to me. Basically spring data cosmos db throws the following exception, here the stacktrace:
Error creating bean with name 'xxxRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: type of id field must be String or Integer
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:636) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
... 19 common frames omitted
Caused by: java.lang.IllegalArgumentException: type of id field must be String or Integer
at com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation.getIdField(CosmosEntityInformation.java:153) ~[spring-data-cosmosdb-2.2.5.jar:na]
at com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation.<init>(CosmosEntityInformation.java:48) ~[spring-data-cosmosdb-2.2.5.jar:na]
at com.microsoft.azure.spring.data.cosmosdb.repository.support.ReactiveCosmosRepositoryFactory.getEntityInformation(ReactiveCosmosRepositoryFactory.java:40) ~[spring-data-cosmosdb-2.2.5.jar:na]
at com.microsoft.azure.spring.data.cosmosdb.repository.support.ReactiveCosmosRepositoryFactory.getTargetRepository(ReactiveCosmosRepositoryFactory.java:46) ~[spring-data-cosmosdb-2.2.5.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:312) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.data.util.Lazy.getNullable(Lazy.java:212) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at com.microsoft.azure.spring.data.cosmosdb.repository.support.ReactiveCosmosRepositoryFactoryBean.afterPropertiesSet(ReactiveCosmosRepositoryFactoryBean.java:61) ~[spring-data-cosmosdb-2.2.5.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
... 29 common frames omitted
@apescione - thanks for sharing the logs. Though cosmosdb always treats the id as string in the backend, but I guess that should not limit us to allow Long
type.
Closing it here as this is being tracked in a separate repo.
I've notice that the class https://github.com/microsoft/spring-data-cosmosdb/blob/master/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosEntityInformation.java#L153
allows to have only string and Integer (plus primitive int) as Id's type. So, choosimg Long or long as Id, the Spring data throws an error IllegalArgumentException. Why not enabling also Long type being Cosmos Db id an string? In many cases, an Id as long could be useful.