dimanche 29 mars 2015

Neet to connect a join table to a separate table



I need to keep record of various businesses their cities and their branches in each city. Each business might be in different cities and in each city might have different branches. Take a bank as an example. It might be in Cities A and B and in city A might have two branches and in city b only one.


I suppose the branch table should have branchid and foreign keys of both primary keys of the join table. In this way I can make sure no branch will be associate to more than one combination of city and business.



Business City
\ /
BusinessID CityID <<join table has primary keys of Business and City tables
|
Branch
BranchID BusinessID CityID


Sample data



Business Table
1
2
3

City Table
A
B
C

Join Table
Business_City
1 A
1 B
2 A
3 C

Branch Table
Business City Branch
1 A I1
1 A I2
1 B I6
2 A I5
3 C I3


My current entities



@Entity
public class Business {
@Id
long id;
@ManyToMany
List<City> cities;
...
}

@Entity
public class City {
@Id
long id;
}

@Entity
public class Branch {
?????
}



Aucun commentaire:

Enregistrer un commentaire