Reputation: 610
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.
Upvotes: 1
Views: 1652
Reputation: 18480
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);
Upvotes: 1