Springboot 1.5.9 springboot 2.2.2 Jpaクエリーで遭遇したピットにアップグレード
22249 ワード
エラーメッセージ
問題解決
エラーの原因はこのクラスにあります.agentServiceRepositoryというインタフェースのソースコードは次のとおりです.
最初の方法はidクエリに基づいてspringboot 2.X以降のidクエリによる戻り結果はいずれもOptionalパッケージでなければならず、以下のように変更すればよい.
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'agentUserProxy': Unsatisfied dependency expressed through field 'agentServiceRes'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'agentServiceRepository': Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError
Caused by: java.lang.IncompatibleClassChangeError: null
at org.springframework.data.jpa.util.JpaMetamodel.lambda$isSingleIdAttribute$4(JpaMetamodel.java:94)
at org.springframework.data.jpa.util.JpaMetamodel$$Lambda$714/814473635.test(Unknown Source)
at java.util.Optional.filter(Optional.java:178)
at org.springframework.data.jpa.util.JpaMetamodel.isSingleIdAttribute(JpaMetamodel.java:94)
at org.springframework.data.jpa.mapping.JpaPersistentPropertyImpl.lambda$new$2(JpaPersistentPropertyImpl.java:110)
at org.springframework.data.jpa.mapping.JpaPersistentPropertyImpl$$Lambda$707/1251996697.get(Unknown Source)
at org.springframework.data.util.Lazy.getNullable(Lazy.java:212)
at org.springframework.data.util.Lazy.get(Lazy.java:94)
at org.springframework.data.jpa.mapping.JpaPersistentPropertyImpl.isIdProperty(JpaPersistentPropertyImpl.java:141)
at org.springframework.data.jpa.mapping.JpaPersistentEntityImpl.returnPropertyIfBetterIdPropertyCandidateOrNull(JpaPersistentEntityImpl.java:72)
at org.springframework.data.jpa.mapping.JpaPersistentEntityImpl.returnPropertyIfBetterIdPropertyCandidateOrNull(JpaPersistentEntityImpl.java:39)
at org.springframework.data.mapping.model.BasicPersistentEntity.addPersistentProperty(BasicPersistentEntity.java:218)
at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:538)
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.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:248)
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:191)
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:85)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$4(RepositoryFactoryBeanSupport.java:295)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport$$Lambda$654/308976247.accept(Unknown Source)
at java.util.Optional.ifPresent(Optional.java:159)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:295)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 99 common frames omitted
問題解決
エラーの原因はこのクラスにあります.agentServiceRepositoryというインタフェースのソースコードは次のとおりです.
public interface AgentServiceRepository
extends JpaRepository<AgentService, String>
{
AgentService findByIdAndOrgi(String paramString, String orgi);
List<AgentService> findByUseridAndOrgiOrderByLogindateDesc(String paramString, String orgi);
@Query(value = "SELECT * FROM uk_agentservice WHERE userid= ?1 AND orgi = ?2 ORDER BY logindate DESC LIMIT 1", nativeQuery = true)
Optional<AgentService> findOneByUseridAndOrgiOrderByLogindateDesc(String userid, String orgi);
AgentService findFirstByUserid(String userid);
Page<AgentService> findByOrgi(String orgi, Pageable paramPageable);
Page<AgentService> findByOrgiAndSatisfaction(String orgi, boolean satisfaction, Pageable paramPageable);
Page<AgentService> findByOrgiAndStatus(String orgi, String status, Pageable paramPageable);
List<AgentService> findByAgentnoAndStatusAndOrgi(String agentno, String status, String orgi);
int countByUseridAndOrgiAndStatus(String userid, String orgi, String status);
List<AgentService> findByUseridAndOrgiAndStatus(String userid, String orgi, String status, Sort sort);
Page<AgentService> findAll(Specification<AgentService> spec, Pageable pageable); //
}
最初の方法はidクエリに基づいてspringboot 2.X以降のidクエリによる戻り結果はいずれもOptionalパッケージでなければならず、以下のように変更すればよい.
Optional<AgentService> findByIdAndOrgi(String paramString, String orgi);