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. 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
@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
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.
public interface ComunicacionRepository extends BaseRepository<Comunicacion, Long> {
List<Comunicacion> findByFechaPublicacionDesdeBefore(Date date);
}
I've tried using @Query and I get the same result. 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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.