Spring Data Rest error: Caused by: org.springframework.data.mapping.PropertyReferenceException: No property name found for type Project

huangapple go评论44阅读模式
英文:

Spring Data Rest error: Caused by: org.springframework.data.mapping.PropertyReferenceException: No property name found for type Project

问题

以下是已翻译的内容:

这是我的项目实体:

import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name="project")
//@Data is bugged
@Getter
@Setter
public class Project {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "project_name")
    @NotNull
    @NotEmpty
    private String projectName;

    @Column(name = "description")
    private String description;

    @Column(name = "stage")
    private String stage;


    @ManyToMany(fetch = FetchType.LAZY,
                cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH})
    @JoinTable(
            name="project_employee",
            joinColumns=@JoinColumn(name="project_id"),
            inverseJoinColumns=@JoinColumn(name="employee_id")
    )
    private Set<Employee> employees;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "project")
    private Set<Ticket> tickets;

    public void addEmployee(Employee employee) {
        if(employees == null) {
            employees = new HashSet<Employee>();
        }
        employees.add(employee);
    }

}

这是我的项目存储库,我尝试实现一个搜索查询方法:

import com.ghevi.bugtracker.entity.Project;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestParam;

@CrossOrigin("http://localhost:4200")
@RepositoryRestResource(collectionResourceRel = "projects", path = "projects")
public interface ProjectRepository extends JpaRepository<Project, Long> {
    Page<Project> findByNameContaining(@RequestParam("projectName") String projectName, Pageable pageable);
}

这是错误的堆栈跟踪: 错误堆栈跟踪链接
(因为垃圾邮件过滤器的原因,必须使用 pastebin)

我不明白为什么会出错,因为项目实体确实有一个projectName属性。

英文:

This is my project entity:

import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.Set;
@Entity
@Table(name=&quot;project&quot;)
//@Data is bugged
@Getter
@Setter
public class Project {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = &quot;id&quot;)
private Long id;
@Column(name = &quot;project_name&quot;)
@NotNull
@NotEmpty
private String projectName;
@Column(name = &quot;description&quot;)
private String description;
@Column(name = &quot;stage&quot;)
private String stage;
@ManyToMany(fetch = FetchType.LAZY,
cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH})
@JoinTable(
name=&quot;project_employee&quot;,
joinColumns=@JoinColumn(name=&quot;project_id&quot;),
inverseJoinColumns=@JoinColumn(name=&quot;employee_id&quot;)
)
private Set&lt;Employee&gt; employees;
@OneToMany(cascade = CascadeType.ALL, mappedBy = &quot;project&quot;)
private Set&lt;Ticket&gt; tickets;
public void addEmployee(Employee employee) {
if(employees == null) {
employees = new HashSet&lt;Employee&gt;();
}
employees.add(employee);
}
}

This is my project repository where i try to implement a search query method:

import com.ghevi.bugtracker.entity.Project;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestParam;
@CrossOrigin(&quot;http://localhost:4200&quot;)
@RepositoryRestResource(collectionResourceRel = &quot;projects&quot;, path = &quot;projects&quot;)
public interface ProjectRepository extends JpaRepository&lt;Project, Long&gt; {
Page&lt;Project&gt; findByNameContaining(@RequestParam(&quot;projectName&quot;) String projectName, Pageable pageable);
}

This is the stack trace of the error: https://pastebin.com/7qzJNd25
(Got to use pastebin because of spam filter)

I dont understand since the project entity does have a projectName property.

答案1

得分: 1

You need to use exact same field name in method naming means findByProjectNameContaining as your field name is projectName

Page<Project> findByProjectNameContaining(@RequestParam("projectName") String projectName, Pageable pageable);

英文:

You need to use exact same field name in method naming means findByProjectNameContaining as your field name is projectName

Page&lt;Project&gt; findByProjectNameContaining(@RequestParam(&quot;projectName&quot;) String projectName, Pageable pageable);

huangapple
  • 本文由 发表于 2020年8月1日 04:58:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/63199012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定