英文:
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="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);
}
}
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("http://localhost:4200")
@RepositoryRestResource(collectionResourceRel = "projects", path = "projects")
public interface ProjectRepository extends JpaRepository<Project, Long> {
Page<Project> findByNameContaining(@RequestParam("projectName") 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<Project> findByProjectNameContaining(@RequestParam("projectName") String projectName, Pageable pageable);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论