We have a repository with standard features:
save findOne exists findAll count delete deleteAll I need to add a new, login search. And I can not figure out how to create it correctly. I looked on the Internet, but understood little. Did, as written here http://devcolibri.com/4149 Here is the essence:
package ua.samuliak.messenger.entity; import org.hibernate.annotations.GenericGenerator; import javax.persistence.*; @Entity @Table(name = "\"user\"") public class User { @Id @GeneratedValue(generator = "increment") @GenericGenerator(name = "increment", strategy = "increment") private long id; @Column(nullable = false, length = 20) private String login; @Column(nullable = false, length = 20) private String password; @Column(length = 2) private String country; @ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.PERSIST}) @JoinColumn(name = "room_id") private Room room; public Room getRoom() { return room; } public void setRoom(Room room) { this.room = room; } public User() {} public long getId() { return id; } public void setId(long id) { this.id = id; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } } Part of the code from the controller:
..... @RequestMapping(value = "/user/{name}", method = RequestMethod.GET) @ResponseBody public User getUserByName(@PathVariable("name") String userLogin){ return userService.getByLogin(userLogin); } ..... And repository
package ua.samuliak.messenger.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import ua.samuliak.messenger.entity.User; public interface UserRepository extends JpaRepository<User, Long>{ @Query("FROM User WHERE login = :name ") User findByName(String name); } Help with the repository, please! How to make a search query by name correctly, what would the entity return?
I put it a little wrong, there is no error as such, just the request itself is underlined (I lay down the screen) and writes "FROM" unexpected. And when requesting a server (see the code with the controller), it does not issue the user by login, but writes such an error (screen No. 2).

New problem
31-May-2016 11:08:59.847 SEVERE [http-apr-8080-exec-35] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions < 8.; nested exception is java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions < 8.] with root cause java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions < 8.