title: Spring Data JPA Null pointer Exception
body: <p><a href="https://i.stack.imgur.com/dPOoU.jpg" rel="nofollow noreferrer">enter image description here</a>I am new to Spring Boot Data JPA repository. This is my first application with JPA. I am trying to get data from DB. But which returns NULL.</p>
  
  <p><strong>Entity File</strong></p>
  
  <pre><code>import javax.persistence.*;
  
  @Entity
  @Table(name = "TASK_DETAILS")
  public class TaskDetails {
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "TASK_DETAILS_ID")
  private long taskDetailsId;
  
  @Column(name = "TASK_NAME")
  private String TaskName;
  
  @Column(name = "TASK_POLLING_TIME")
  private int TaskTime;
  
  @Column(name = "TASK_FILE")
  private String TaskClassFile;
  
  @Column(name = "TASK_STATUS")
  private String TaskStatus;
  
  public long getTaskDetailsId() {
  return taskDetailsId;
  }
  
  public void setTaskDetailsId(long taskDetailsId) {
  this.taskDetailsId = taskDetailsId;
  }
  
  public String getTaskName() {
  return TaskName;
  }
  
  public void setTaskName(String taskName) {
  TaskName = taskName;
  }
  
  public int getTaskTime() {
  return TaskTime;
  }
  
  public void setTaskTime(int taskTime) {
  TaskTime = taskTime;
  }
  
  public String getTaskClassFile() {
  return TaskClassFile;
  }
  
  public void setTaskClassFile(String taskClassFile) {
  TaskClassFile = taskClassFile;
  }
  
  public String getTaskStatus() {
  return TaskStatus;
  }
  
  public void setTaskStatus(String taskStatus) {
  TaskStatus = taskStatus;
  }
  }
  </code></pre>
  
  <p><strong>Repository File</strong></p>
  
  <pre><code>import java.util.Collection;
  import java.util.List;
  import java.util.Optional;
  
  @Repository
  public interface TaskDetailsRepository extends JpaRepository&lt;TaskDetails, String&gt; {
  
  TaskDetails findByTaskDetailsId(final long id);
  }
  </code></pre>
  
  <p><strong>My Main Method</strong></p>
  
  <pre><code>@Service
  public class ImportAmazonData {
  
  @Autowired
  private TaskDetailsRepository taskDetailsRepositoryDAO;
  
  public void getProductsFromAmazonStore(JobExecutionContext context) throws ClassNotFoundException {
  final long taskID = (long) context.getJobDetail().getJobDataMap().get("taskId");
  
  TaskDetails taskDetails = taskDetailsRepositoryDAO.findByTaskDetailsId(taskID);
  System.out.println("Result : " + taskDetails.getTaskClassFile());
  }
  }
  </code></pre>
  
  <p><strong>ProductSync File</strong> </p>
  
  <pre><code>   import com.example.Schedular.AmazonSync.ImportAmazonData;
      import org.quartz.Job;
      import org.quartz.JobExecutionContext;
      import org.quartz.JobExecutionException;
      import org.springframework.stereotype.Component;
  
      public class ProductSync implements Job {
  
      @Autowired
      private ImportAmazonData importAmazonData;
  
      @Override
      public void execute(JobExecutionContext context) throws JobExecutionException {
          try {
              importAmazonData.getProductsFromAmazonStore(context);
          } catch (ClassNotFoundException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Here i am trying to get the TaskDetails by id. But my taskDetailsRepositoryDAO was null. Here i have attached my error log. Please let me know. Thanks in advance.</p>
  
  <p><strong>ERROR LOG</strong></p>
  
  <pre><code>
  java.lang.NullPointerException: null
      at com.example.Schedular.AmazonSync.ImportAmazonData.getProductsFromAmazonStore(ImportAmazonData.java:20) ~[classes/:na]
      at com.example.Schedular.SyncData.ProductSync.execute(ProductSync.java:16) ~[classes/:na]
      at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.3.2.jar:na]
      at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.3.2.jar:na]
  
  </code></pre>