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 4018716
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:01:02+00:00 2026-05-20T10:01:02+00:00

I have been trying for last 3 days still i am not able to

  • 0

I have been trying for last 3 days still i am not able to solve my problem

I have Person Class

@SuppressWarnings("rawtypes")
 @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="person")
 @JoinColumn(name="person_id")
 public Set<Book> books = new HashSet<Book>();

class Book

book_id
person_id

In my JSP form i have

<c:forEach items="${BookList}" var="var1" varStatus="counter">
     <input type="checkbox" name="books[${counter.index}].book_id" value="${var1.book_id}" >${var1.book_name}</input>
    </c:forEach>

I am inserting the books in table depending upon the check boxes
The book list is populated from refrenceData model.

COntroller

@RequestMapping(value = "/persons/add", method = RequestMethod.GET)
    public String getAdd(Model model) {
        logger.debug("Received request to show add page");

        // Create new Person and add to model
        // This is the formBackingOBject
        model.addAttribute("personAttribute", new Person());

        // This will resolve to /WEB-INF/jsp/addpage.jsp
        return "hibernate/addpage";
    }



@RequestMapping(value = "/persons/add", method = RequestMethod.POST)
public String add(@Valid @ModelAttribute("personAttribute") Person person, BindingResult result) {
        logger.debug("Received request to add new person");

        if (result.hasErrors()) 
    return "hibernate/addpage";
        else
        personService.add(person);

    // This will resolve to /WEB-INF/jsp/addedpage.jsp
        return "hibernate/addedpage";
    }

Now if i have single Book object then this works ok and data is entered in DB but if i have set then it says invalid property book[1]

After searching a lot on SO and Google i leart that i have two option

PropertyEditor
AutoPopulatingList

I don’t know how to use them in my case. Can anyone help me , where do i have to use them and how to use it

  • 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-05-20T10:01:03+00:00Added an answer on May 20, 2026 at 10:01 am

    Look at this question Bind objects in a Set collection

    You need to use another type of Collection. I’d recommend to use a List instead of a Map. When you send from the form a parameter with a name like:

    name="books[0].book_id"
    

    SpringMVC will look in the property called books (which is a Set for you) and then it will try to get the first element by doing books.get(0). Set don’t have a get because Set has not an order.

    For the implementation of the list you can use AutoPopulatingList. It is an implementation of a lazy List which will create an object if it doesn’t exist. For example if you invoke books[0].id and you haven’t added a book in the position 0 of the list it will throw a NullPointerException, but if you use AutoPopulatingList it will create a new Book and addd it in that position if that position is empty.

    public List<Book> books = new AutoPopulatingList<Book>(new ElementFactory<Book>() {
        @Override
        public Book createElement(final int index) throws ElementInstantiationException {
             //call the constructor as you need
             return new Book();
        }       
    });
    

    if you you are going to instanciate it with the default constructor of Book (that is Book()), you can use a syntax like this one:

    public List<Book> books = new AutoPopulatingList<Book>(Book.class);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem I have been trying to solve for last three days.
I have an interesting problem here I've been trying to solve for the last
During last three days I have been trying to solve Project Euler 15 in
I have been trying to understand and solve this problem for the last three
I have been trying to sort this problem out for the last few days.
For the last 3 days, I have been trying to sort an array, but
Last couple of days i have been trying to make listpreference work on my
For the last few days, I have been trying to use Python for some
I'm very experienced in C/C++/Objective-C and over the last few days have been trying
I've been trying to figure this problem out for the last 2 days already,

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.