[英]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.