title: Update database table from jsp form
body: <p>I have a jsp view where I'm displaying a set of parameters (checkboxes and test fields) that the user can modify and save the changes. 
  The parameters are stored in an entity called "PropertiesEnvironment" that extends "Environment" entity.
  I am able to display the parameters correctly but I couldn't figure how I can save the changes once the user makes a modification.</p>
  
  <p>I've tried doing it with servlets but I always get Null pointer error.</p>
  
  <p><strong>Here is my PropertiesEnvironment Entity:</strong></p>
  
  <pre><code>@Entity
  public class PropertiesEnvironment extends Environment implements Serializable {
      private PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
  
      public PropertiesEnvironment() {
      }
  
      private Long lastPurgeTimestamp;
  
      @Column
      public Long getLastPurgeTimestamp() {
          return lastPurgeTimestamp;
      }
  
      public void setLastPurgeTimestamp(Long lastPurgeTimestamp) {
          this.lastPurgeTimestamp = lastPurgeTimestamp;
      }
  
    @Column(length=500000)
    @Lob
    @Type(type = "serializable")
    public Map&lt;String, Serializable&gt; getProperties() {
          return propertiesConfiguration.getProperties();
      }
      public void setProperties(Map&lt;String, Serializable&gt; properties) {
          propertiesConfiguration.setProperties(properties);
      }
      public int getIntValue(String tag, String defaultValue) {
          return propertiesConfiguration.getIntValue(tag, defaultValue);
      }
      public int getIntValue(String tag) {
          return propertiesConfiguration.getIntValue(tag);
      }
      public boolean getBooleanValue(String property, String defaultValue) {
          return propertiesConfiguration.getBooleanValue(property, defaultValue);
      }
      public boolean getBooleanValue(String tag) {
          return propertiesConfiguration.getBooleanValue(tag);
      }
      public void setBooleanValue(String tag, boolean value) {
          propertiesConfiguration.setBooleanValue(tag, value);
      }
      public String getStringValue(String tag) {
          String v = propertiesConfiguration.getStringValue(tag);
          return v == null ? "" : v;
      }
      public String getStringValue(String tag, String value) {
          return propertiesConfiguration.getStringValue(tag, value == null ? "" : value);
      }
      public void setStringValue(String tag, String value) {
          propertiesConfiguration.setStringValue(tag, value);
      }
      public void setIntValue(String tag, int value) {
          propertiesConfiguration.setIntValue(tag, value);
      }
  </code></pre>
  
  <p><strong>And this is my Environment Entity</strong></p>
  
  <pre><code>@Entity
  @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
  @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
  @Table(name = "environment")
  public class Environment implements Serializable, Cloneable {
  
      private static final long serialVersionUID = -6347094896871928639L;
  
      private long id;
  
      @ManyToOne
      private String code;
  
      private String name;
  
      private Set&lt;String&gt; terminals = new TreeSet&lt;String&gt;();
  
      @Id//(generate = GeneratorType.AUTO)
      @GeneratedValue
      public long getId() {
          return id;
      }
  
      public void setId(long id) {
          this.id = id;
      }
  
      @Column(length = 30)
      public String getCode() {
          return code;
      }
  
      public void setCode(String code) {
          this.code = code;
      }
  
      @Column(length = 50)
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p><strong>My controller:</strong></p>
  
  <pre><code>    @Controller
  public class PickingParametersController  {
      @Autowired
      private EnvironmentRepository environmentRepository;
      private PickingParametersRepository pickingParametersRepository;
      private EnvironmentPropertiesService environmentPropertiesService;
  
      public PickingParametersController(EnvironmentRepository environmentRepository , PickingParametersRepository pickingParametersRepository) {
          this.environmentRepository = environmentRepository;
          this.pickingParametersRepository = pickingParametersRepository;
      }
  
      @RequestMapping(value = {"/picking"}, method = RequestMethod.POST)
      public String select(HttpServletRequest request , Model model2) throws ServletException, IOException {
          String selected = request.getParameter("dropDownList");// get param from kendo dropdownlist
  
          List&lt;PropertiesEnvironment&gt; environmentList = pickingParametersRepository.findByCode(selected); // load params by id
          model2.addAttribute("properties",environmentList);
          return "picking";
      }
  @RequestMapping(value = "success", method = RequestMethod.POST)
  public String save(@ModelAttribute("propertiesEnvironment") PropertiesEnvironment propertiesEnvironment) {
      environmentPropertiesService.update(propertiesEnvironment);
      return "success";
  }
  
      @RequestMapping(value = {"/picking"}, method = RequestMethod.GET)
      public String page(Model model) {
          List&lt;PropertiesEnvironment&gt; codeList = (List&lt;PropertiesEnvironment&gt;) environmentRepository.findAll();
          model.addAttribute("code",codeList);
          return "picking";
      }
  }
  </code></pre>
  
  <p><strong>My repository interface</strong></p>
  
  <pre><code>@Repository
  public interface PickingParametersRepository extends CrudRepository&lt;PropertiesEnvironment, String&gt; {
      @Query("SELECT E.properties FROM Environment E WHERE E.code = :code")
      List&lt;PropertiesEnvironment&gt; findByCode (@Param("code") String code);
  </code></pre>
  
  <p><strong>EnvironmentProperties Service</strong></p>
  
  <pre><code>public interface EnvironmentPropertiesService {
  
  public  PropertiesEnvironment update(PropertiesEnvironment propertiesEnvironment);
  </code></pre>
  
  <p><strong>EnvironmentPropertiesServiceImpl</strong></p>
  
  <pre><code>    @Transactional
  @Service("environmentPropertiesService")
  public class EnvironmentPropertiesServiceImpl implements EnvironmentPropertiesService{
  
      @Autowired
      private PickingParametersRepository pickingParametersRepository;
  
      @Override
      public PropertiesEnvironment update (PropertiesEnvironment propertiesEnvironment){
          return pickingParametersRepository.save(propertiesEnvironment);
      }
  </code></pre>
  
  <p><strong>And finally the code lines from my JSP page:</strong></p>
  
  <pre><code>&lt;form method="post" modelAttribute="pickingparam" action="${pageContext.request.contextPath }/success"&gt;
  
                                               &lt;c:forEach items="${properties}" var="p"&gt;
  
                                                   ID &lt;input type="text" value="${p.id}"&gt;&lt;br&gt;
                                                   Channel &lt;input type="text" value="${p.channel}"&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
                                                   Total Lines Assignement    &lt;input type="checkbox" name="totalLinesAssignment" value="1" id="id1"
                                                   &lt;c:if test="${p.totalLinesAssignment == 'true'}"&gt;checked="checked"&lt;/c:if&gt;/&gt;&lt;br&gt;
                                                   Total Lines Support    &lt;input type="checkbox" name="totalLinesSupport" value="1" id="id10"
                                                   &lt;c:if test="${p.totalLinesSupport == 'true'}"&gt;checked="checked"&lt;/c:if&gt;/&gt;&lt;br&gt;
                                                   Total Pick Units Assignement   &lt;input type="checkbox" name="totalPickUnitsAssignment" value="2" id="id2"
                                                   &lt;c:if test="${p.totalPickUnitsAssignment == 'true'}"&gt;checked="checked"&lt;/c:if&gt;/&gt;&lt;br&gt;
                                                   Total Pick Units Support   &lt;input type="checkbox" name="totalPickUnitsSupport" value="3" id="id3"
                                                   &lt;c:if test="${p.totalPickUnitsSupport == 'true'}"&gt;checked="checked"&lt;/c:if&gt;/&gt;&lt;br&gt;
                                                   Inventory Pick Location Activity Type  &lt;input type="text" value="${p.inventoryPickLocationActivityType}"&gt;&lt;br&gt;
                                                   Inventory Stock Location Activity Type  &lt;input type="text" value="${p.inventoryStockLocationActivityType}"&gt;&lt;br&gt;
                                                   Inventory Last Digits EAN  &lt;input type="text" value="${p.inventoryLastDigitsEAN}"&gt;&lt;br&gt;
                                                   Inventory Last Digits SSCC &lt;input type="text" value="${p.inventoryLastDigitsSSCC}"&gt;&lt;br&gt;
  
                                              &lt;input type="submit" value="Save"/&gt;
  
  
  
                                              &lt;/c:forEach&gt;
  
                                             &lt;/form&gt;
  </code></pre>
  
  <p><em>Here's the stack trace:</em></p>
  
  <blockquote>
    <p>java.lang.NullPointerException: null
        at com.vocognition.ui.web.controller.PickingParametersController.save(PickingParametersController.java:62) ~[classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_181]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_181]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.32.jar:8.5.32]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]</p>
  </blockquote>
  
  <p>Any ideas on how I canmake the updates to the database please?
  Thanks for any help!</p>