Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8611527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:23:56+00:00 2026-06-12T04:23:56+00:00

I have a question to ask. I am getting this error while trying to

  • 0

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.

Here are my data:

table 'property':

id
name

table 'features'

id
title
property_id [not null]

Entity Property

 @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<PropertyFeature> 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<PropertyFeature> getFeatures() {
        return features;
    }

    public void setFeatures(Set<PropertyFeature> features) {
        this.features = features;
    }   

}

Entity PropertyFeature

@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;
    }
}

SPRING CONTROLLER

@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<PropertyFeature> test = new ArrayList<PropertyFeature>();
        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";
    }   

} 

JSP FORM:

<form:form method="post" commandName="property">

Name <form:input path="name" type="text" name="name" value="" />
Features
<form:select multiple="true" path="features">
    <form:options items="${testList}" itemValue="title" itemLabel="title"/>
</form:select>

<input type="submit" name="submit" value="Test" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:23:57+00:00Added an answer on June 12, 2026 at 4:23 am

    Hibernate needs a foreign key on property_feature to join back to the ManyToOne mapped property. You have not provided a column through the use of @JoinColumn therefore Hibernate has created one in your schema using its defaulting mechanism. This is described here in section 2.2.5.3.1.4.

    You have mapped Property as being non-optional, therefore Hibernate expects that you always set a Property on your PropertyFeature before saving. You have added the PropertyFeature into the list on Property but you have not set the Property on PropertyFeature.

    I would suggest adding a method on to your property class as follows:

    public void addFeature(PropertyFeature feature) {
      feature.setProperty(this);
      features.add(feature);
    }
    

    then in your controller you can write:

    Property property = propertyServiceImpl.load(12L);
    property.addFeature(new PropertyFeature("Feature 1"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to ask this question because I'm stuck, and I think its because
I have to really ask this question as I donot know Python. Following are
[i meant to ask this question on StackOverflow...] I have been using VisualSVN Server
I'm fairly new to this, and don't have anyone else to ask. I'm attempting
guys I have two question to ask, they're easy, but bothering me for a
Well,i have a weird question to ask,sometimes when designing a form and using lots
I've only have a simple question to ask : Is it possible to call
I have seen stackoverflow ask question page they disable button until my postback event
I have a question that I'm ashamed to ask, but I'm going to have
I have a SQL question that i need to ask the experts. To be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.