title: findById() not working on spring boot and Jpa
body: <p>My main class is :   </p>
  
  <pre><code> package com.ashwin.jpafirst;
  
      import com.ashwin.jpafirst.model.Person;
      import com.ashwin.jpafirst.reposit.PersonJpaRepository;
      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.boot.CommandLineRunner;
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
  
      @SpringBootApplication
      public class JpafirstApplication implements CommandLineRunner {
  
          private Logger logger= LoggerFactory.getLogger(this.getClass());
  
          @Autowired
          PersonJpaRepository personJpaRepository;
  
          public static void main(String[] args)
  
          {
              SpringApplication.run(JpafirstApplication.class, args);
          }
  
          @Override
          public void run(String... args) throws Exception {
              // TODO Auto-generated method stub
  
              logger.info("User id is ",personJpaRepository.findById(2));
  
          }
  
      }
  </code></pre>
  
  <p>Person.java</p>
  
  <pre><code>package com.ashwin.jpafirst.model;
  import java.util.Date;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="person")
  public class Person {
  
  
          @Id
          @GeneratedValue
          private int id;
  
          @Column(name="name")
          private String name;
          private String location;
          private Date dateOfBirth;
  
          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 getLocation() {
              return location;
          }
          public void setLocation(String location) {
              this.location = location;
          }
          public Date getDateOfBirth() {
              return dateOfBirth;
          }
          public void setDateOfBirth(Date dateOfBirth) {
              this.dateOfBirth = dateOfBirth;
          }
          public Person(int id, String name, String location, Date dateOfBirth) {
  
              this.id = id;
              this.name = name;
              this.location = location;
              this.dateOfBirth = dateOfBirth;
          }
  
          public Person() {
  
          }
  
  
      }
  </code></pre>
  
  <p>my application properties is:</p>
  
  <pre><code>## Spring DATASOURCE (DataSourceAutoConfiguration &amp; DataSourceProperties)
  spring.datasource.url = jdbc:mysql://localhost:3306/jpaintro
  spring.datasource.username = root
  spring.datasource.password =
  
  
      ## Hibernate Properties
      # The SQL dialect makes Hibernate generate better SQL for the chosen database
      spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
  
      # Hibernate ddl auto (create, create-drop, validate, update)
      spring.jpa.hibernate.ddl-auto = update
  </code></pre>
  
  <p>PersonJpaRepository.java</p>
  
  <pre><code>package com.ashwin.jpafirst.reposit;
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  
  import com.ashwin.jpafirst.model.Person;
  import org.springframework.stereotype.Repository;
  import org.springframework.transaction.annotation.Transactional;
  
  
  @Repository
  @Transactional
  public class PersonJpaRepository {
  
      //connects to Databse
      @PersistenceContext
      EntityManager entityManager;
  
      public Person findById(int id) {
          return entityManager.find(Person.class, id);
      }
  
  }
  </code></pre>
  
  <p>I have also data saved in database as:</p>
  
  <p><a href="https://i.stack.imgur.com/ifjEf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ifjEf.png" alt="enter image description here"></a></p>
  
  <p>But when I try to receive the Person object by Id using </p>
  
  <pre><code>logger.info("User id is ",personJpaRepository.findById(2));
  </code></pre>
  
  <p>I am just getting as :</p>
  
  <p><a href="https://i.stack.imgur.com/23apu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/23apu.png" alt="enter image description here"></a></p>
  
  <p>As Person object needs to print there,but the code is successfully compiling but I am not getting the information regarding the person.My code has no error but it is not retrieving the data.Why is the Person object not printing in the console?</p>