简体   繁体   中英

Spring and Hibernate : How to implement more than 1 POJO in one form

I am new to Spring framework.

I have a case I couldn't solve my self. I have two POJO, ie: PersonData and Address. Both of this POJO save on separated table on a database. I mapped both of the POJO to the database tables using Hibernate.

My problem is how to store the POJOs data(PersonData and Address) to relevant tables using one form.

My question is : How to insert data from one form to multiple tables using hibernate?

Create one object that holds both of the POJOs and set this as your form. For example you could create an object with something like;

class PersonFormObejct {
  private PersonData personData;
  private Address address;

  // getters and setters
}

Make this your form object rather than either of the two POJOs.

You should be able to access both of the member objects using the notation personFormObject.personData.foo or personFormObject.address.postcode. This is assuming that you named the form object personFormObject of course.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM