Не удалось найти атрибут с указанным именем в этом ManagedType [неизвестно] - PullRequest
0 голосов
/ 24 апреля 2020

У меня есть объект с именем

public class Customer implements Auditable {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "SellerID")
private Long id;

@Embedded
private AuditSection auditSection = new AuditSection();
......
......
}

@Embeddable
public class AuditSection implements Serializable {
private static final long serialVersionUID = -1934446958975060889L;
@Temporal(TemporalType.TIMESTAMP)
  @Column(name = "DateCreated")
  private Date dateCreated;

  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "DateModified")
  private Date dateModified;
  ......
  }

Я пытаюсь использовать критерииBuilder и Predicates для поиска

 predicates.add(criteriaBuilder.and(criteriaBuilder.notEqual(root.get("modifiedDate"), new Date)));

Здесь я получаю исключение

org.springframework.dao.InvalidDataAccessApiUsageException: Unable to locate Attribute  with the the given name [modifiedDate] on this ManagedType [unknown]; nested exception is java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [modifiedDate] on this ManagedType [unknown]
    at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:374) ~[spring-orm-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:256) ~[spring-orm-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:528) ~[spring-orm-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61) ~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242) ~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153) ~[spring-tx-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178) ~[spring-data-jpa-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at com.sun.proxy.$Proxy187.findAll(Unknown Source) ~[?:?]
    at com.sawce.core.service.customer.impl.CustomerEnquiryServiceImpl.findByPagingCriteria(CustomerEnquiryServiceImpl.java:73) ~[sawce-core-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at com.sawce.core.service.customer.impl.CustomerEnquiryServiceImpl$$FastClassBySpringCGLIB$$8026ffc6.invoke(<generated>) ~[sawce-core-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:769) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) ~[spring-aop-5.2.0.RELEASE.jar:5.2.0.RELEASE]

Я упомянул некоторые подобные вопросы, но я не нашел решения.

1 Ответ

2 голосов
/ 24 апреля 2020

Имя атрибута: dateModified not ifiedDate .

Таким образом, код должен выглядеть следующим образом:

predicates.add(criteriaBuilder
  .and(criteriaBuilder.notEqual(
       root.get("auditSection").get("dateModified"), new Date)));
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...