Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NotReadablePropertyException while using SpringData projection
NotReadablePropertyException while using SpringData projection [message #1810059] Tue, 30 July 2019 07:46
Wojciech Korczynski is currently offline Wojciech KorczynskiFriend
Messages: 1
Registered: July 2019
Junior Member
I have the following problem with using Spring Data on EclipseLink - I use projections in order to get selected properties of the objects in database. I have an entity named "Campaign":
    @Entity
    @Table(name = "campaign")
    public class Campaign implements Serializable {


        @Id
        @NotNull
        private String id;
        @NotNull
        private CampaignState state = CampaignState.NEW;
        
        // getters and setters...

    }


CampaignState is some enum. Then, I added the following projection:

    public interface CampaignStateView {
        CampaignState getState();
    }


...which I use in my repository:
    public interface CampaignRepository extends
            JpaRepository<Campaign, String>,
            QuerydslPredicateExecutor<Campaign> {

        @Query("SELECT DISTINCT c.state AS state FROM Campaign c")
        List<CampaignStateView> findDistinctStates();
    }


I use this repository in my service:
    @ApplicationScoped
    public class CampaignDataService {

        private CampaignRepository campaignRepository;

        // for CDI proxy
        public CampaignDataService() {
        }

        @Inject
        public CampaignDataService(CampaignRepository campaignRepository) {
            this.campaignRepository = campaignRepository;
        }

        public Collection<CampaignState> findStates() {
            return campaignRepository.findDistinctStates().stream()
                    .map(CampaignStateView::getState)
                    .collect(Collectors.toList());
        }

    }


But, unfortunately, when I call a method findStates() from the service, I get the following exception:

Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'state' of bean class [campaign.CampaignState]: Could not find field for property during fallback access! 
         at org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper.getPropertyValue(DirectFieldAccessFallbackBeanWrapper.java:58) 
         at org.springframework.data.projection.PropertyAccessingMethodInterceptor.invoke(PropertyAccessingMethodInterceptor.java:73) 
         at org.springframework.data.projection.ProjectingMethodInterceptor.invoke(ProjectingMethodInterceptor.java:64) 
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) 
         at org.springframework.data.projection.ProxyProjectionFactory$TargetAwareMethodInterceptor.invoke(ProxyProjectionFactory.java:245) 
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) 
         at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) 
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) 
         at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) 
         at com.sun.proxy.$Proxy301.getState(Unknown Source) 
         at campaign.CampaignDataService$$Lambda$491.000000006DCDF7C0.apply(Unknown Source) 
         at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:204) 
         at java.util.Vector$VectorSpliterator.forEachRemaining(Vector.java:1451) 
         at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:523) 
         at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:513) 
         at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:719) 
         at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:245) 
         at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:510) 
         at campaign.CampaignDataService.findStates(CampaignDataService.java:153)
         ... 118 more 


I get this error only on EclipseLink - on Hibernate everything works fine... Thank you in advance for any help!
Previous Topic:Composite foreign key with a fixed value generates wrong SQL
Next Topic:EclipseLink PreUpdate on OneToOne Relationship not persisted
Goto Forum:
  


Current Time: Tue Apr 23 13:35:08 GMT 2024

Powered by FUDForum. Page generated in 0.03032 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top