java ee - Persisting a Joint Table in JPA -


i have 3 entities, trader, portfolio , member. each trader has portfolio , portfolio can have many members. have set following relationships. i'm not sure how use jointable created, i.e. portfolio_portfolioid , members_memberid. i'd associate each portfolid member id's, i'm not sure how go this. how jointable data persisted?

my portfolio class

@entity @table(name="portfolio") @namedquery( name="findportfoliobytrader", query="select p portfolio p" + " trader = :trader" ) public class portfolio {  @id @generatedvalue private integer portfolioid; @temporal(timestamp) private date lastupdate; private integer balance; private trader trader; private collection<member> members;  public portfolio() {      this.lastupdate = new date(); } public portfolio(integer balance, trader trader) {      this.lastupdate =  new date();     this.balance = balance;     this.trader = trader; }  public integer getportfolioid() {     return portfolioid; }  public void setportfolioid(integer portfolioid) {     this.portfolioid = portfolioid; }  public date getlastupdate() {     return lastupdate; }  public void setlastupdate(date lastupdate) {     this.lastupdate = lastupdate; }  @manytomany @jointable(         name="member_portfolio",         joincolumns=             @joincolumn(name="member_memberid", referencedcolumnname="memberid"),         inversejoincolumns=             @joincolumn(name="portfolio_portfolioid", referencedcolumnname="portfolioid") ) public collection<member> getmembers() {     return members; }  public void setmembers(collection<member> members) {     this.members = members; }  @onetoone(cascade=all, mappedby="portfolio") public trader gettrader()  {     return trader; }  public void settrader(trader trader) {     this.trader = trader; }  public integer getbalance() {     return balance; }  public void setbalance(integer balance) {     this.balance = balance; }   } 

my member class

@entity @table(name="member") @namedquery( name="findallmembers", query="select m member m " +   "order m.memberid" ) public class member implements java.io.serializable { /**  *   */ private static final long serialversionuid = -468520665316481235l;  private string memberid; private string forename; private string surname; private integer position; private integer majority; private integer ipo; private integer questions; private integer answers; private party party; private date lastupdate; private char status; private collection<portfolio> portfolios; private collection<askorder> askorders; private collection<bidorder> bidorders;   public member() {          this.lastupdate = new date();     }   public member(string memberid,string forename, string surname, integer position,           integer majority, integer ipo, integer questions, integer answers, party party) {         this.memberid = memberid;         this.forename = forename;         this.surname = surname;         this.position = position;         this.majority = majority;         this.ipo = ipo;         this.questions = questions;         this.answers = answers;         this.party = party;         this.lastupdate = new date();         this.askorders = new arraylist<askorder>();         this.bidorders = new arraylist<bidorder>();         this.portfolios = new arraylist<portfolio>();     }      @id     public string getmemberid() {         return memberid;     }      public void setmemberid(string memberid) {         this.memberid = memberid;     }      public char getstatus() {         return status;     }      public void setstatus(char status) {         this.status = status;     }      @temporal(timestamp)     public date getlastupdate() {         return lastupdate;     }       public void setlastupdate(date lastupdate) {         this.lastupdate = lastupdate;     }      public string getforename()     {         return forename;     }      public void setforename(string forename)     {         this.forename = forename;     }      public string getsurname() {         return surname;     }      public void setsurname(string surname) {         this.surname = surname;     }      public integer getposition() {         return position;     }      public void setposition(integer position) {         this.position = position;     }      public integer getmajority() {         return majority;     }      public void setmajority(integer majority) {         this.majority = majority;     }      public integer getipo() {         return ipo;     }      public void setipo(integer ipo) {         ipo = ipo;     }      public integer getquestions() {         return questions;     }      public void setquestions(integer questions) {         this.questions = questions;     }      public integer getanswers() {         return answers;     }      public void setanswers(integer answers) {         this.answers = answers;     }      @manytoone     public party getparty() {         return party;     }      public void setparty(party party) {         this.party = party;     }      @onetomany(cascade=all, mappedby="member")     public collection<askorder> getaskorders()      {         return askorders;     }      public void setaskorders(collection<askorder> orders)     {         this.askorders = orders;     }      @onetomany(cascade=all, mappedby="member")     public collection<bidorder> getbidorders()      {         return bidorders;     }      public void setbidorders(collection<bidorder> bidorders)     {         this.bidorders = bidorders;     }      @manytomany //fixme should many many - done     public collection<portfolio> getportfolios() {         return portfolios;     }      public void setportfolios(collection<portfolio> portfolios) {         this.portfolios = portfolios;     }  } 

    @entity     public class portfolio     {       @id       @generatedvalue       private int id;        @manytomany       @jointable( name = "portfoliomember",         @joincolumns : @joincolumn( name = "portfolio_id", referencedcolumnname="id" ),         @inversejoincolumns : @joincolumn( name = "member_id", referencedcolumnname="id" )       )       private list<member> members;     }      @entity     public class member     {       @id       @generatedvalue       private int id;        @manytomany( mappedby = members )       private list<portfolio> portfolios;     } 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -