Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
This is tge
error
i am getting atthe time of compilation. I am new at spring and not able to understand the error.Plz help me to find out.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepo' defined in com.example.jpa.repository.UserRepo defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List com.example.jpa.repository.UserRepo.findNameLike(java.lang.String)! Reason: Failed to create query for method public abstract java.util.List com.example.jpa.repository.UserRepo.findNameLike(java.lang.String)! No property findName found for type User!; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.example.jpa.repository.UserRepo.findNameLike(java.lang.String)! No property findName found for type User!
This is my Repository class
According to that the error in the @Query But i am getting how to fix and wher is my mistake.
i have created a tavle called user1 in mysql.
package com.example.jpa.repository;
import java.util.List;
import javax.persistence.criteria.CriteriaBuilder.In;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.example.jpa.entity.User;
@Repository
public interface UserRepo extends JpaRepository<User, Integer> {
public List<User> findByAgeGreaterThanEqual(int age) ;
public List<User> findByAgeIn(int age);
public List<User> findByNameOrderByName(String name);
@Modifying
@Query (value="select * from user1",nativeQuery=true)
public List<User> getAllUser();
This is my Entity class
package com.example.jpa.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
//@Table(name = "user")
public class User {
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
private String city;
private String status;
public User() {
super();
public User(int id, String name, String city, String status) {
super();
this.id = id;
this.name = name;
this.city = city;
this.status = status;
public int getId() {
return id;
public void setId(int id) {
this.id = id;
public String getName() {
return name;
public void setName(String name) {
this.name = name;
public String getCity() {
return city;
public void setCity(String city) {
this.city = city;
public String getStatus() {
return status;
public void setStatus(String status) {
this.status = status;
This is my main application main class
package com.example.jpa;
import java.util.List;
import java.util.Optional;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import com.example.jpa.entity.User;
import com.example.jpa.repository.UserRepo;
@SpringBootApplication
public class SpringApplicaton1Application {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SpringApplicaton1Application.class, args);
UserRepo repo = context.getBean(UserRepo.class);
User user = new User();
user.setId(1);
user.setCity("Delhi");
user.setName("Ramesh");
user.setStatus("Java Developer");
List<User> users= repo.getAllUser();
users.forEach(n->{
System.out.println(n);
This is my Application.property file
spring.datasource.name=test
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/practice
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect
spring.jpa.hibernate.use-new-id-generator-mappings= false
spring.jpa.hibernate.ddl-auto=update
–
–
i was solving this problem by add these annotation in model class
@Table //is a corresponding table that matches that entity in the database
@Entity // for specifies class is an entity and is mapped to a database table.
@Data // for getter and seter
public class UserModel {
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.