引起:org.springframework.data.mapping.PropertyReferenceException:找不到类型Log

时间:2017-11-10 14:59:25

标签: java spring hibernate jpa spring-data-jpa

我一直收到这个错误:

引起:org.springframework.data.mapping.PropertyReferenceException:找不到类型为Log的属性orderBydateaddedDesc

而我似乎无法找到它为什么不起作用。 findAllLogs()方法工作正常。

有什么想法吗? 任何帮助,将不胜感激。谢谢。

LogRepository.java

package ma.polytechnique.cctv.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import ma.polytechnique.cctv.model.Log;

public interface LogRepository extends JpaRepository<Log, Long> {
    public List<Log> findAllByOrderBydateaddedDesc();

}

LogService.java

package ma.polytechnique.cctv.service;

import java.util.List;

import ma.polytechnique.cctv.model.Log;

public interface LogService {
    void save(Log log);

    List<Log> findAllLogs();

    List<Log> findAllByOrderBydateaddedDesc();
}

LogServiceImpl.java

package ma.polytechnique.cctv.service;

import ma.polytechnique.cctv.model.Log;
import ma.polytechnique.cctv.repository.LogRepository;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogRepository logRepository;


    @Override
    public void save(Log log) {
        logRepository.save(log);
    }


    @Override
    public List<Log> findAllLogs(){
        return logRepository.findAll();
    }

    @Override
    public List<Log> findAllByOrderBydateaddedDesc(){
        return logRepository.findAllByOrderBydateaddedDesc();
    }
}

Log.java

package ma.polytechnique.cctv.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


@Entity
@Table(name="log")
public class Log {

    @Id
    @Column(name="idlog")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int idlog;

    @ManyToOne
    @JoinColumn(name = "user_id")
    private User user;


    private String videotitle;

    private Date dateadded;

    private Date dateedited;

    private Date datedeleted;

    public int getIdlog() {
        return idlog;
    }

    public void setIdlog(int idlog) {
        this.idlog = idlog;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getVideotitle() {
        return videotitle;
    }

    public void setVideo(String videotitle) {
        this.videotitle = videotitle;
    }

    public Date getDateadded() {
        return dateadded;
    }

    public void setDateadded(Date dateadded) {
        this.dateadded = dateadded;
    }

    public Date getDateedited() {
        return dateedited;
    }

    public void setDateedited(Date dateedited) {
        this.dateedited = dateedited;
    }

    public Date getDatedeleted() {
        return datedeleted;
    }

    public void setDatedeleted(Date datedeleted) {
        this.datedeleted = datedeleted;
    }


    @Override
    public String toString() {
        return "Log [idlog=" + idlog + ", username=" + user.toString() + ", video title=" + videotitle + ", dateadded=" + dateadded + "]";
    }

}

0 个答案:

没有答案