Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.25k stars 1.93k forks source link

[BUG]Failed to instantiate interface using constructor NO_CONSTRUCTOR with arguments #40396

Open harrisonhong14 opened 1 month ago

harrisonhong14 commented 1 month ago

Describe the bug Failed to instantiate interface using constructor NO_CONSTRUCTOR with arguments when using crudrepository findById

Exception or Stack Trace

org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate com.guidedchoice.accounts.interfaces.IAccountGeneric using constructor NO_CONSTRUCTOR with arguments 
    at org.springframework.data.mapping.model.ReflectionEntityInstantiator.instantiateClass(ReflectionEntityInstantiator.java:142)
    Suppressed: The stacktrace has been enhanced by Reactor, refer to additional information below: 
Error has been observed at the following site(s):
    *__checkpoint ⇢ HTTP GET "/api/institutions/job?accountId=2010596&jobId=d45ac7e8-6791-4bb0-9164-85abe8c835ba" [ExceptionHandlingWebHandler]
Original Stack Trace:
        at org.springframework.data.mapping.model.ReflectionEntityInstantiator.instantiateClass(ReflectionEntityInstantiator.java:142)
        at org.springframework.data.mapping.model.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:57)
        at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:98)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.doReadInternal(MappingRedisConverter.java:231)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.readInternal(MappingRedisConverter.java:189)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.readProperty(MappingRedisConverter.java:311)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.lambda$doReadInternal$0(MappingRedisConverter.java:245)
        at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:298)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.doReadInternal(MappingRedisConverter.java:237)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.readInternal(MappingRedisConverter.java:189)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.readCollectionOrArray(MappingRedisConverter.java:827)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.readProperty(MappingRedisConverter.java:293)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.lambda$doReadInternal$0(MappingRedisConverter.java:245)
        at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:298)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.doReadInternal(MappingRedisConverter.java:237)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.readInternal(MappingRedisConverter.java:189)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.readProperty(MappingRedisConverter.java:311)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.lambda$doReadInternal$0(MappingRedisConverter.java:245)
        at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:298)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.doReadInternal(MappingRedisConverter.java:237)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.read(MappingRedisConverter.java:183)
        at org.springframework.data.redis.core.convert.MappingRedisConverter.read(MappingRedisConverter.java:114)
        at org.springframework.data.redis.core.RedisKeyValueAdapter.get(RedisKeyValueAdapter.java:290)
        at org.springframework.data.keyvalue.core.KeyValueTemplate.lambda$findById$3(KeyValueTemplate.java:241)
        at org.springframework.data.keyvalue.core.KeyValueTemplate.execute(KeyValueTemplate.java:314)
        at org.springframework.data.keyvalue.core.KeyValueTemplate.findById(KeyValueTemplate.java:239)
        at org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository.findById(SimpleKeyValueRepository.java:98)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)

To Reproduce Save item to crudrepository and then try to retrieve it with findById function

Code Snippet

AutoLinkJobEntity autoLinkJobEntity = AutoLinkJobEntityBuilder.autoLinkJobEntityBuilder();
AutoLinkJobEntity savedAutoLinkJobEntity = autoLinkJobRepo.save(autoLinkJobEntity);
AutoLinkJobEntity foundAutoLinkJobEntity =  autoLinkJobRepo.findById(autoLinkJobEntity.getId()).get();

Expected behavior Should be able to retrieve the item using findById without NO_CONSTRUCTOR error

Setup (please complete the following information):

Additional context We are saving an item that has redisHash annotation on it. When using the datasource: url: …;authentication=ActiveDirectoryDefault; configuration locally, everything seems to work fine but when deployed into Kubernetes, I get an error when trying to findById saying there is an issue with NO_CONSTRUCTOR. However, using authentication=ActiveDirectoryMSI; Seems to allow it to work on Kubernetes. I feel like ActiveDirectoryDefault should work even when deployed though.

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

github-actions[bot] commented 1 month ago

@chenrujun @moarychan @netyyyy @saragluna

github-actions[bot] commented 1 month ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

saragluna commented 1 month ago

Hi @harrisonhong14, thanks for reaching out, but seems like this com.guidedchoice.accounts.interfaces.IAccountGeneric is irrelevant to mssql or AzureAD auth. Could you help provide more information?

harrisonhong14 commented 1 month ago

Yea the AutoLinkJobEntity has the field variable IAccountGeneric which is an interface so that's the only relevance. All I am trying to do is save this autlinkjobentity to a redis hash, which is does successfully and I can see it in redis when I check, but when I use the findById function, its throwing that NO_CONSTRUCTOR error. This is only happening when we use the authentication=ActiveDirectoryDefault; in the datasource.url, when it is deployed to Kubernetes. Locally, I can get the value from redis with it but I need to set it to ActiveDirectoryMSI when its deployed to not get the error

saragluna commented 1 month ago

Hi @harrisonhong14, which library does this findById function belong to? Is it the spring-data-redis or anything related to mssql?

harrisonhong14 commented 1 month ago

Oh sorry, I forgot to add the dependency spring-data-jpa which uses spring-data-commons-3.2.6 that has the CrudRepository that uses findById

saragluna commented 1 month ago

@harrisonhong14, could you help provide a minimal reproducible project for us to troubleshoot?