1

hibernate

I have an entity: Factories

@Entity
public class Factories extends BaseEntity {

    @Id
    @SequenceGenerator(name = "factories_id_seq", sequenceName = "factories_id_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "factories_id_seq")
    private Integer id;


    @ElementCollection
    private Set<String> emails = new HashSet<String>();

    //get set...
}

In thymeleaf to add email to factories,

 <table id="emailsTable" class="table table-striped table-hover responsive">
      <thead>
          <tr>
              <th th:text="#{value}">Value</th>
              <th></th>
          </tr>
      </thead>
      <tbody>
          <tr th:each="email, stat : *{emails}">
              <td><input type="text" class="form-control" th:placeholder="#{email.placeholder}" placeholder="Name" th:field="*{emails[__${stat.index}__]}" /></td>
              <td class="align-middle"><button type="button" class="btn btn-default pull-right delete"><i class="fas fa-trash-alt"></i></button></td>
          </tr>
      </tbody>
</table>

When I try to save, I get

org.springframework.beans.InvalidPropertyException: Invalid property 'emails[0]' of bean class [com.lcm.model.Factories]: Property referenced in indexed property path 'emails[0]' is neither an array nor a List nor a Map; returned value was [[]]

1 Answer 1

1

it's not possible because set have no order...check this post there are a few alternative...

Need help with binding Set with Spring MVC form

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.