Quote:
So using the foreign key in one-to-many association will not only pollute the class B with unnecessary foreign key
the foreign key is not unnecessary In this scenario, as it is the only field to hold the relation information.
Quote:
it also affect the locking version?
Yes, see here
Example association a with b :
Code:
with join-table:
update A set version=1 where id=1 and version=0
insert into A_B (A_id, B_id) values (1, 1)
Code:
with foreign key:
update A set version=1 where id=1 and version=0
update B set assA_id=1, version=1 where id=1 and version=0
As you can see the association with foreign key also increments implicitly the version of b from 0 to 1.
Quote:
The join table also come in with the trade off of the extra table in db and more complex in the configuration.
Yes, the schema on database gets a little bit more complicate.
Quote:
Is the performance will be affected by using the join table way of association?
It depends on the database you are using and if the join-table has the proper indexes working
(primary key (A_id, B_id) and unique (B_id) in our case)
Modern database should no have performance problems for executing simple join-queries,
so generally you should take a decision based on your needs for locking and concurrency.