Anand
Anand

Reputation: 369

How to insert form inputs into multiple tables using Spring MVC and JPA?

I have to insert product details. I have multiple bean classes which are generated from tables but all the fields are in a single html form. How could I map those form elements to different bean classes and how could I get those form elements in controller?.

My Bean classes are

Category
    private Long id;
    private String description;
    private String name;

ProductAttribute 
    private String description;
    private String name;

CategoryAttributeMapping
    private Category category;
    private ProductAttribute productAttribute ;

Could any one help me?

Upvotes: 0

Views: 1381

Answers (1)

Alexandru Tomuta
Alexandru Tomuta

Reputation: 177

You can make some kind of proxy Object that has all of those fields, map the path in the HTML form to that object and in some service layer, you can break it in those 3 Entity classes and save them in the Database.

And on a side note(IF you're using Hibernate), what you have there is @ManyToMany (i suppose) mapping. You don't need to create the 3rd class to map those 2 Entities.

Upvotes: 1

Related Questions