Spring Hibernate Relation Mapping -
i'm looking in 1 of project.
i'm having company class , bank class.
company class , bank class mapped using many many relation using hibernate.
how start? i'm done creating company module inserting data table , same bank. how show mapping between both?
flow goes - add company -> edit/update -> add bank previous company detail -> bank add/update -> view all, needed show list of companies , respective banks.
i assume use junction table done this:
company.class
@manytomany(fetch = fetchtype.lazy, cascade = cascadetype.all) @jointable(name = "nameofjunctiontable", catalog = "yourdatabasename", joincolumns = { @joincolumn(name = "companyid", nullable = false, updatable = false) }, inversejoincolumns = { @joincolumn(name = "bankid", nullable = false, updatable = false) }) private collection<bank> banks;
bank.class
@manytomany(fetch = fetchtype.lazy, mappedby = "banks") private collection<company> companies;
Comments
Post a Comment