简体   繁体   English

Spring Data-在找到类型java.util.Date之后没有属性

[英]Spring Data - No property after found for type java.util.Date

I've been struggling with something for the last 2 days and can't fugure it up. 在过去的两天里,我一直在苦苦挣扎,无法解决问题。 I'm using Java 7, Spring data jpa 1.0 and Hibernate 4.3.1.Final. 我正在使用Java 7,Spring数据jpa 1.0和Hibernate 4.3.1.Final。 I'm trying to make a query that would fetch based on date. 我正在尝试进行基于日期的查询。 I've trimmed the code to make readable 我整理了代码以使其可读

All dates are java.util.Date 所有日期均为java.util.Date

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Informe {
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    @Column(name = "ID")
    private Long id;

    @OneToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name="COMUNICACION_ID")
    private Comunicacion comunicacion;

    public Comunicacion getComunicacion() {
        return comunicacion;
    }

    public void setComunicacion(Comunicacion comunicacion) {
        this.comunicacion = comunicacion;
    }
}

@Entity
@Table(name = "REGISTRO_CALIFICACION")
public class RegistroCalificacion extends Informe {
}

@Entity
@Table(name = "COMUNICACION")
public class Comunicacion {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;
    @Basic
    @javax.persistence.Column(name = "FECHA_PUBLICACION_DESDE", nullable = false, insertable = true,     updatable = true, length = 19, precision = 0)
    private Date fechaPublicacionDesde;

    public Date getFechaPublicacionDesde() {
        return fechaPublicacionDesde;
    }

    public void setFechaPublicacionDesde(Date fechaPublicacionDesde) {
        this.fechaPublicacionDesde = fechaPublicacionDesde;
    }
}

public interface InformeRepository extends BaseRepository<Informe, Long> {
    List<RegistroCalificacion> findByComunicacionFechaPublicacionDesdeAfter(Date date);

}

This throws this exception while creating the beans 创建bean时会抛出此异常

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property after found for type java.util.Date

But If I access directly to Comunicación, like below, it works fine. 但是,如果我像下面这样直接访问Comunicación,它就可以正常工作。

public interface ComunicacionRepository extends BaseRepository<Comunicacion, Long> {

   List<Comunicacion> findByFechaPublicacionDesdeBefore(Date date);
}

I've tried using @Query and I get the same result. 我尝试使用@Query并得到相同的结果。 Any thoughts? 有什么想法吗?

I think this should be your repository: 我认为这应该是您的存储库:

public interface RegistroCalificacionRepository extends BaseRepository<RegistroCalificacion, Long> {

    List<Comunicacion> findByFechaPublicacionDesdeBefore(Date date);
}

Because you want the RegistroCalificacion to be queried not Comunicacion. 因为您希望查询RegistroCalificacion而不是Comunicacion。

Could you add 你能补充吗

@Temporal(TemporalType.DATE)

@javax.persistence.Column(name = "FECHA_PUBLICACION_DESDE", nullable = false, insertable = true,     updatable = true, length = 19, precision = 0)
@Temporal(TemporalType.DATE)
private Date fechaPublicacionDesde;

It should be: 它应该是:

public interface InformeRepository extends BaseRepository<Informe, Long> {
    List<RegistroCalificacion> findByComunicacionFechaPublicacionDesde(Date date);

}

You are adding the word "After" at the end of the name of your method, and the repository can not find a property named like that on your "Comunicacion" entity. 您要在方法名称的末尾添加单词“ After”,并且存储库无法在“ Communicacion”实体上找到类似名称的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Data Rest中的java.util.Date - java.util.Date in Spring Data Rest 如何使用Spring Data Cassandra将java.util.Date值插入Cassandra日期类型列中? - How to insert java.util.Date values into Cassandra date type column using Spring Data Cassandra? 找不到类型的 java.util.Date bean - java.util.Date bean of type could not be found 在java.util.Date类型上找不到方法toGregorianCalendar() - Method toGregorianCalendar() cannot be found on java.util.Date type 春季启动2:ConverterNotFoundException:未找到能够从类型[java.time.ZonedDateTime]转换为类型[java.util.Date]的转换器 - Spring boot 2 : ConverterNotFoundException: No converter found capable of converting from type [java.time.ZonedDateTime] to type [java.util.Date] Spring数据休息,url param中的java.util.Date? - Spring data rest, java.util.Date in url param? 带有java.util.Date的QueryDSL Spring数据Web支持 - QueryDSL Spring data web support with java.util.Date @Value用于在Spring 3中初始化java.util.Date - @Value for initializing java.util.Date in Spring 3 找不到能够从类型 [java.time.LocalDateTime] 转换为类型 [java.util.Date] 的转换器 - No converter found capable of converting from type [java.time.LocalDateTime] to type [java.util.Date] 无法将 java.lang.String 类型的属性值转换为所需类型 java.util.Date - Failed to convert property value of type java.lang.String to required type java.util.Date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM