0

I have a standalone app that is Up and getting below error when calling "http://localhost:8080/user/person/1604438222".(trying to get person id details from db)

2019-03-01 11:23:34.296 ERROR 52000 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [1604438222] did not match expected type [java.lang.Integer (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [1604438222] did not match expected type [java.lang.Integer (n/a)]] with root cause

java.lang.IllegalArgumentException: Parameter value [1604438222] did not match expected type [java.lang.Integer (n/a)] at org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:54) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final] at org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:27) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]

  1. Controller class :

    @RestController
    @RequestMapping("/user")
    public class UserController {
    
    
        @Autowired
        PersonRepository personRepository; 
    
         @GetMapping("/person/{prsId}")
         public Person getPerson(@PathVariable Long prsId) {
              return personRepository.findByPrsId(prsId);
         }
    }
    
  2. Repository :

    @Repository
    public interface PersonRepository extends  CrudRepository<Person, Long>
    {
        Person findByPrsId(Long Id);
    
    }
    
  3. POJO

    @Entity
    @Table(name = "Person")
    public class Person {
    
        @Column(name = "Prs_Id")
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Integer prsId;
    
        @Column(name = "P_Email_Internet_Addr", nullable = true, length = 255)
        private String email;
    
    
        protected Person() {
        }
    
    
        public Integer getPrsId() {
            return prsId;
        }
    
        public void setPrsId(Integer prsId) {
            this.prsId = prsId;
        }
    
        public String getEmail() {
            return email;
        }
    
        public void setEmail(String email) {
            this.email = email;
        }
    
    
        @Override
            public String toString() {
                    return "User [prsId=" + prsId + ", email=" + email 
                     + "]";
            }
        }
    
Nirav
  • 602
  • 1
  • 10
  • 28
vicky
  • 149
  • 2
  • 7
  • 21
  • "*I have a standalone app that is Up and getting below error when calling ....*" - That's unfortunate. What's your question? – Turing85 Mar 01 '19 at 19:49
  • You define the PrsId as an Integer but use a Long to try and find it. 2304438636 is also larger than the Max signed Integer value. – Compass Mar 01 '19 at 19:49

2 Answers2

2

2,147,483,647 is the value for Integer.MAX_VALUE

2,304,438,636 is too big to be contained in an Integer variable

Use Long instead for your ids in general. Or even better, the primitive long since your IDs should ideally never be null

Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89
0

You are using Integer in POJO and Long in Repository and Controller. Change either all of them to use Integer or Long.

Nirav
  • 602
  • 1
  • 10
  • 28