Wednesday, March 15, 2017

No property coalesce(wAHimage found for type WAHImage

Leave a Comment

I have a model "WAHImage" with the following getter and setter:

@Column(name = "is_deleted") public boolean getIsDeleted() { return isDeleted; } public void setIsDeleted(boolean isDeleted) { this.isDeleted = isDeleted; } 

And a Spring Data JPA Repository:

public interface ImageRepository extends JpaRepository<WAHImage, Long>,         QueryDslPredicateExecutor<WAHImage> {     Page<WAHImage> findAllByIsDeleted(boolean isDeleted, Pageable page); } 

And a Spring Boot (1.5.1) Service, which has ImageRepository autowired in its constructor:

@Service public class ImageService {     private ImageRepository imageRepository;     public Page<WAHImage> get(Pageable pageable) {         return imageRepository.findAllByIsDeleted(false, ImagePredicates.orderByName(pageable));     } 

ImagePredicates.orderByName(Pageable) looks like:

static QPageRequest orderByName(Pageable page) {      QWAHImage image = QWAHImage.wAHImage;     QWACensusImpl name = image.census;     QSpecimenImpl specimen = image.specimen;     OrderSpecifier genus = name.name1.coalesce(specimen.genus).asc();     OrderSpecifier species = name.name2.coalesce(specimen.species).asc();     OrderSpecifier rank = name.rank4.coalesce(             name.rank3.coalesce(specimen.rank)).asc();     OrderSpecifier infraspecies = name.name4.coalesce(             name.name3.coalesce(specimen.infraspecies)).asc();      OrderSpecifier[] sort = new OrderSpecifier[] {             genus, species, rank, infraspecies     };      return new QPageRequest(page.getPageNumber(), page.getPageSize(), sort); } 

And a Spring Boot Controller:

@Controller public class ImageController {     @GetMapping("/list")     public String list(Pageable pageable, Model model) {         Page<WAHImage> searchResult = imageService.get(pageable);     } } 

Why am I getting No property coalesce(wAHImage found for type WAHImage!? Do I have to handle nulls in the coalesce() statements in ImagePredicates.orderByName? If so, how?

org.springframework.data.mapping.PropertyReferenceException: No property coalesce(wAHImage found for type WAHImage! at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329) at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272) at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) at org.springframework.data.jpa.repository.query.QueryUtils.toJpaOrder(QueryUtils.java:542) at org.springframework.data.jpa.repository.query.QueryUtils.toOrders(QueryUtils.java:496) at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:195) at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:143) at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:52) at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88) at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.createQuery(PartTreeJpaQuery.java:144) at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.doCreateQuery(PartTreeJpaQuery.java:79) at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:190) at org.springframework.data.jpa.repository.query.JpaQueryExecution$PagedExecution.doExecute(JpaQueryExecution.java:184) at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:85) at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:116) at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:106) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:483) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) at com.sun.proxy.$Proxy143.findAllByIsDeleted(Unknown Source) at x.y.z.image.ImageService.get(ImageService.java:120) at x.y.z.image.ImageService$$FastClassBySpringCGLIB$$6d3a7999.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:652) at x.y.z.image.ImageService$$EnhancerBySpringCGLIB$$21037cfe.get(<generated>) at x.y.z.controller.image.ImageController.list(ImageController.java:132) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) 

Update: added entity and generated QueryDSL class.

Full WAHImage model class.

@Entity @Table(name = "image") public class WAHImage extends PersistentImpl {     private WACensusImpl census = new WACensusImpl();     private SpecimenImpl specimen = new SpecimenImpl();     private UserImpl author = new UserImpl();     private LookupImpl copyright = new LookupImpl();     private LookupImpl allowedUse = new LookupImpl();     private String imageType;     private String description;     private String locality;     private String imageNotes;     private String authorCode;     private Set<LookupImpl> keywords = new HashSet<>();     private boolean isDeleted = Boolean.FALSE;     private static final long serialVersionUID = 4187307837824004338L;      @ManyToOne(fetch = FetchType.LAZY)     @JoinColumn(name = "census_id", nullable = true)     public WACensusImpl getCensus() {         return census;     }      public void setCensus(WACensusImpl census) {         this.census = census;     }      @ManyToOne(fetch = FetchType.LAZY)     @JoinColumn(name = "specimen_id", nullable = true)     public SpecimenImpl getSpecimen() {         return specimen;     }      public void setSpecimen(SpecimenImpl specimen) {         this.specimen = specimen;     }      @ManyToOne(fetch = FetchType.LAZY)     @JoinColumn(name = "author_id", nullable = false)     public UserImpl getAuthor() {         return author;     }      public void setAuthor(UserImpl author) {         this.author = author;     }      @ManyToOne(fetch = FetchType.LAZY)     @JoinColumn(name = "copyright_id", nullable = false)     public LookupImpl getCopyright() {         return copyright;     }      public void setCopyright(LookupImpl copyright) {         this.copyright = copyright;     }      @ManyToOne(fetch = FetchType.LAZY)     @JoinColumn(name = "allowed_use_id", nullable = false)     public LookupImpl getAllowedUse() {         return allowedUse;     }      public void setAllowedUse(LookupImpl allowedUse) {         this.allowedUse = allowedUse;     }      @Column(name = "image_type")     public String getImageType() {         return imageType;     }      public void setImageType(String imageType) {         this.imageType = imageType;     }      @Column(name = "description")     public String getDescription() {         return description;     }      public void setDescription(String description) {         this.description = description;     }      @Column(name = "locality")     public String getLocality() {         return locality;     }      public void setLocality(String locality) {         this.locality = locality;     }      @Column(name = "image_notes")     public String getImageNotes() {         return imageNotes;     }      public void setImageNotes(String imageNotes) {         this.imageNotes = imageNotes;     }      @Column(name = "author_code")     public String getAuthorCode() {         return authorCode;     }      public void setAuthorCode(String authorCode) {         this.authorCode = authorCode;     }      @ManyToMany(cascade = CascadeType.ALL)     @JoinTable(name = "image_keyword", joinColumns = { @JoinColumn(name = "image_id") },                inverseJoinColumns = {@JoinColumn(name = "keyword_id", unique = false) })     public Set<LookupImpl> getKeywords() {         return keywords;     }      public void setKeywords(Set<LookupImpl> keywords) {         this.keywords = keywords;     }      @Column(name = "is_deleted")     public boolean getIsDeleted() {         return isDeleted;     }      public void setIsDeleted(boolean isDeleted) {         this.isDeleted = isDeleted;     }      @Override     public String toString() {         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)                 .append(getId())                 .append(getAuthor())                 .append(getImageType())                 .toString();     } } 

Full QueryDSL class.

/**  * QWAHImage is a Querydsl query type for WAHImage  */ @Generated("com.querydsl.codegen.EntitySerializer") public class QWAHImage extends EntityPathBase<WAHImage> {      private static final long serialVersionUID = 2019538268L;      private static final PathInits INITS = PathInits.DIRECT2;      public static final QWAHImage wAHImage = new QWAHImage("wAHImage");      public final x.y.z.db.impl.QPersistentImpl _super = new x.y.z.db.impl.QPersistentImpl(this);      //inherited     public final NumberPath<Long> addedBy = _super.addedBy;      //inherited     public final DateTimePath<java.util.Date> addedOn = _super.addedOn;      public final x.y.z.lookup.impl.QLookupImpl allowedUse;      public final x.y.z.user.impl.QUserImpl author;      public final StringPath authorCode = createString("authorCode");      public final x.y.z.reference.census.impl.QWACensusImpl census;      public final x.y.z.lookup.impl.QLookupImpl copyright;      public final StringPath description = createString("description");      //inherited     public final NumberPath<Long> id = _super.id;      public final StringPath imageNotes = createString("imageNotes");      public final StringPath imageType = createString("imageType");      public final BooleanPath isDeleted = createBoolean("isDeleted");      public final SetPath<x.y.z.lookup.impl.LookupImpl, x.y.z.lookup.impl.QLookupImpl> keywords = this.<x.y.z.lookup.impl.LookupImpl, x.y.z.lookup.impl.QLookupImpl>createSet("keywords", x.y.z.lookup.impl.LookupImpl.class, x.y.z.lookup.impl.QLookupImpl.class, PathInits.DIRECT2);      public final StringPath locality = createString("locality");      public final x.y.z.reference.specimen.impl.QSpecimenImpl specimen;      //inherited     public final NumberPath<Long> updatedBy = _super.updatedBy;      //inherited     public final DateTimePath<java.util.Date> updatedOn = _super.updatedOn;      public QWAHImage(String variable) {         this(WAHImage.class, forVariable(variable), INITS);     }      public QWAHImage(Path<? extends WAHImage> path) {         this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));     }      public QWAHImage(PathMetadata metadata) {         this(metadata, PathInits.getFor(metadata, INITS));     }      public QWAHImage(PathMetadata metadata, PathInits inits) {         this(WAHImage.class, metadata, inits);     }      public QWAHImage(Class<? extends WAHImage> type, PathMetadata metadata, PathInits inits) {         super(type, metadata, inits);         this.allowedUse = inits.isInitialized("allowedUse") ? new x.y.z.lookup.impl.QLookupImpl(forProperty("allowedUse")) : null;         this.author = inits.isInitialized("author") ? new x.y.z.user.impl.QUserImpl(forProperty("author")) : null;         this.census = inits.isInitialized("census") ? new x.y.z.reference.census.impl.QWACensusImpl(forProperty("census")) : null;         this.copyright = inits.isInitialized("copyright") ? new x.y.z.lookup.impl.QLookupImpl(forProperty("copyright")) : null;         this.specimen = inits.isInitialized("specimen") ? new x.y.z.reference.specimen.impl.QSpecimenImpl(forProperty("specimen")) : null;     } } 

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment