title: Null pointer exception spring boot jpa
body: <p>I am trying to pass values to the persistence layer in a springboot application using jpa. However, each time I get a null pointer exception despite that I see that the object to be persisted is well formed. I have my code snippets below.</p>
  
  <p><strong>AlertRepository</strong></p>
  
  <pre><code>public interface AlertRepository extends JpaRepository&lt;Alert, Integer&gt;{
   }
  </code></pre>
  
  <p><strong>AlertController</strong></p>
  
  <pre><code>@Controller
  public class AlertController {
  
  @Autowired
  private AlertRepository alertRepository;    
  @GetMapping(path="/add") // Map ONLY GET Requests
  public @ResponseBody String addNewAlert (@RequestParam Alert cAlert) {
      Alert alert = new Alert();
      alert.setAlert(cAlert.getAlert());
      alert.setAttack(cAlert.getAttack());
      alertRepository.save(alert);
  
      .....
      .....
      return "Saved";
  }
  </code></pre>
  
  <p><strong>Get_Save_Alert</strong></p>
  
  <pre><code>ApiResponse hh = zapClient.core.numberOfAlerts(target);
          List&lt;Alert&gt; alertList = zapClient.getAlerts(target, 0, 0);
          // zapClient.core.alerts(target, start, count);
          System.out.println("the number of alerts is : " + hh);
          de.cavas.model.Alert cavasAlert = new de.cavas.model.Alert();
          for (Alert alert : alertList) {
              cavasAlert.setRisk(alert.getRisk().toString());
              cavasAlert.setConfidence(alert.getConfidence().toString());
              cavasAlert.setUrl((alert.getUrl().toString()));
              cavasAlert.setParam(alert.getParam().toString());
              cavasAlert.setSolution(alert.getSolution());
              cavasAlert.setCweid(String.valueOf(alert.getCweId()));
              cavasAlert.setWascid(String.valueOf(alert.getWascId()));
              cavasAlert.setAttack(alert.getAttack());
              cavasAlert.setDescription(alert.getDescription());
              cavasAlert.setName(alert.getName());
              cavasAlert.setPluginId(alert.getPluginId());
              cavasAlert.setReference(alert.getReference());
  
  
              controller.addNewAlert(cavasAlert);
              }
  </code></pre>
  
  <p>Here is the exception stacktrace:</p>
  
  <pre><code>Exception : null
  java.lang.NullPointerException
  at de.cavas.repository.AlertController.addNewAlert(AlertController.java:26)
  at de.cavas.SecurityTest.preRegistrationTest(SecurityTest.java:281)
  at 
  de.cavas.InstanceRegistry.handleTempRegistration(InstanceRegistry.java:250)
  at de.cavas.InstanceRegistry.register(InstanceRegistry.java:155)
  </code></pre>
  
  <p>Line 26 in the trace refers to  the line  <code>alertRepository.save(alert)</code> in the <code>AlertController Class</code>.</p>
  
  <p><strong>Update</strong>
  I have also provided the application.yml file incase there is something "fishy" I cannot see !</p>
  
  <pre><code>server:
  port: 8761
  eureka:
      client:
            registerWithEureka: false
           fetchRegistry: false
  server:
        waitTimeInMsWhenSyncEmpty: 0    
  spring:
     datasource:
         url: jdbc:mysql://sssss:500/vulncorrelate?useSSL=false
     username: ss
     password: ss
     platform: mysql
     initialize: false
   jpa:
     database-platform: org.hibernate.dialect.MySQLDialect
     generate-ddl: true
     spring.jpa.show-sql: true
     hibernate.ddl-auto: update
  </code></pre>
  
  <p><strong>update 2</strong> - the <code>Alert</code> entity class</p>
  
  <pre><code>@Entity
  @JsonInclude(JsonInclude.Include.NON_NULL)
  
  public class Alert {
  
  String microserviceName;
  String microservicePort;
  String microserviceIpAddress;
  String microserviceId;
  String timeStamp;
  
  @JsonProperty("sourceid")
  private String sourceid;
  
  
  @JsonIgnore
  @JsonProperty("other")
  private String other;
  
  @JsonProperty("method")
  private String method;
  
  @Lob
  @JsonProperty("evidence")
  private String evidence;
  
  @JsonProperty("pluginId")
  private String pluginId;
  
  @JsonProperty("cweid")
  private String cweid;
  
  @JsonProperty("confidence")
  private String confidence;
  
  @JsonProperty("wascid")
  private String wascid;
  
  @JsonProperty("description")
  private String description;
  
  @JsonProperty("messageId")
  private String messageId;
  
  @Lob
  @JsonProperty("url")
  private String url;
  
  @Lob
  @JsonProperty("reference")
  private String reference;
  
  @JsonProperty("solution")
  private String solution;
  
  @Lob
  @JsonProperty("alert")
  private String alert;
  
  @Lob
  @JsonProperty("param")
  private String param;
  
  @Lob
  @JsonProperty("attack")
  private String attack;
  @JsonProperty("name")
  private String name;
  @JsonProperty("risk")
  private String risk;
  @JsonProperty("id")
  private int id;
  
  @JsonProperty("sourceid")
  public String getSourceid() {
      return sourceid;
  }
  
  public Alert(String microserviceName, String microservicePort, String 
  microserviceIpAddress, String microserviceId,
          String timeStamp, String sourceid, String other, String method, 
  String evidence, String pluginId,
          String cweid, String confidence, String wascid, String description, 
  String messageId, String url,
          String reference, String solution, String alert, String param, 
  String attack, String name, String risk,
          int id) {
      super();
      this.microserviceName = microserviceName;
      .....
  }
  
  public Alert() {
      // TODO Auto-generated constructor stub
  }
  
  ...... //setters and getters
   }
  </code></pre>