当前位置: 首页 > 知识库问答 >
问题:

无法找到此ManagedType上给定名称的属性[未知]

梁才
2023-03-14

我有一个实体叫做

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;
  ......
  }

我正在尝试使用criteriaBuilder和谓词进行搜索

 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个答案

宰父子安
2023-03-14

属性的名称是dateModified而不是modifiedDate。

因此,代码必须如下所示:

predicates.add(criteriaBuilder
  .and(criteriaBuilder.notEqual(
       root.get("auditSection").get("dateModified"), new Date)));
 类似资料: