title: SPRING JSP Form with Hibernate
body: <p>I have a question to ask. I am getting this error while trying to save a new property into the database. Column 'property_id' cannot be null. An exception happens when tryint to save features list into the database. For some reason there is not relation between the property that was inserted and features. Property_id does not exist inside the object PropertyFeature.</p>
  
  <p>Here are my data: </p>
  
  <pre><code>table 'property':
  
  id
  name
  
  table 'features'
  
  id
  title
  property_id [not null]
  </code></pre>
  
  <p>Entity Property</p>
  
  <pre><code> @Table(name = "property")
  public class Property extends...{
  
      @Column(name = "name", nullable = true)
      private String name;    
  
      @OneToMany(mappedBy = "property", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
      private Set&lt;PropertyFeature&gt; features;  
  
  
      public Property() {
      }
  
  
      public Property(long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }   
  
      public Set&lt;PropertyFeature&gt; getFeatures() {
          return features;
      }
  
      public void setFeatures(Set&lt;PropertyFeature&gt; features) {
          this.features = features;
      }   
  
  }
  </code></pre>
  
  <p>Entity PropertyFeature</p>
  
  <pre><code>@Entity
  @Table(name = "property_feature")
  public class PropertyFeature extends ... {
  
  
      @Column(name = "title", nullable = false)
      private String title;
  
      @ManyToOne(optional = false, fetch = FetchType.LAZY)
      private Property property;
  
      public PropertyFeature() {
  
      }
  
      public PropertyFeature(String title) {
          this.title = title;
      }   
  
      public String getTitle() {
          return title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }   
  
      public Property getProperty() {
          return property;
      }
  
      public void setProperty(Property property) {
          this.property = property;
      }
  }
  </code></pre>
  
  <p>SPRING CONTROLLER</p>
  
  <pre><code>@Controller
  @RequestMapping(value="/account")
  public class AccountController {
  
      @Autowired
      PropertyServiceImpl propertyServiceImpl;
  
      @RequestMapping(method = RequestMethod.GET, value = "/test")
      public String accountPage(HttpServletRequest request, HttpServletResponse response, ModelMap model) {       
  
  
          Property property = propertyServiceImpl.load(12L);
  
          ArrayList&lt;PropertyFeature&gt; test = new ArrayList&lt;PropertyFeature&gt;();
          test.add(new PropertyFeature("Feature 1"));
          test.add(new PropertyFeature("Feature 2"));
          test.add(new PropertyFeature("Feature 3"));
  
          model.put("property", property);
          model.put("testList", test);
  
          return "/test";
      }   
  
      @RequestMapping(method = RequestMethod.POST, value = "/test")
      public String accountPost(HttpServletRequest request, HttpServletResponse response, Property property) {        
  
          propertyServiceImpl.update(property);       
  
          return "/test";
      }   
  
  } 
  </code></pre>
  
  <p>JSP FORM:</p>
  
  <pre><code>&lt;form:form method="post" commandName="property"&gt;
  
  Name &lt;form:input path="name" type="text" name="name" value="" /&gt;
  Features
  &lt;form:select multiple="true" path="features"&gt;
      &lt;form:options items="${testList}" itemValue="title" itemLabel="title"/&gt;
  &lt;/form:select&gt;
  
  &lt;input type="submit" name="submit" value="Test" /&gt;
  </code></pre>