Menu

1 to N relationships

2004-09-11
2004-09-19
  • Les Dunaway

    Les Dunaway - 2004-09-11

    Has anyone done this? 
    If so, will you share your approach?

    Les

     
    • Alp Sehic

      Alp Sehic - 2004-09-12

      Hi there,

      what do you mean exactly?...

       
    • Les Dunaway

      Les Dunaway - 2004-09-16

      I mean "Has anyone implemented 1 to n relationships using sql2java?" Example: a Person has multiple addresses(Home, Work, ...) and  telephones (Home, Work, Cell, Beep, Fax, ...) giving two 1-n relationships.

      Rather than stumbling over various painful objects I'd like to take advantage of other's past pain ;-)

      Les

       
    • nr

      nr - 2004-09-17

      If you have 3 tables, Person, Address, Telephone and some foreign keys defined, sql2java will generate some nice code for you so you can call for example:

      (I am just guessing your column names):

      AddressManager.getInstance().loadByPersonid(person.getPersonid())

      TelephoneManager.getInstance().loadByPersonid(person.getPersonid())

       
    • Les Dunaway

      Les Dunaway - 2004-09-18

      RIGHT!  That's the sort of thing I expected.

      I was hoping that someone had actually done such - because AddressManager.getInstance().loadByPersonid(person.getPersonid()) in the 1-n case will return some number of Address objects.  The question is how are they returned, how does one iterate them, ...
      AND, going the other way how does one stuff them into the DB to start with and later (updates).

      Am I right to guess that no one has done more than 1-1 relationships?

      Les

       
    • nr

      nr - 2004-09-19

      > how are they returned

      An array of AddressBean objects

      > how does one iterate them,
      We return them all in the array,.
      We will soon provide iteration feature using 'generics' and rowset

      > how does one stuff them into
      > the DB to start with and later (updates).

      In each manager we generate a save() method... take a look at it, it handles insert and update operation.

      > no one has done more than 1-1 relationships?

      Not sure I understand your concern,
      I personnaly use 1-n relationship and sql2java

       

Log in to post a comment.