hello,
I have to rework an application, so database tables are already existing.
I need some advice on a refactoring.
As the business/domain objects was linked by their database identifiants ( in best case, sometime there's no link although there's a relationship ), i need to add some reference to the convenient objects.
i have to deal with 3 tables.
The table batch and lot are simplified, the table batchlot is as the existant. notice the quantity field in batchlot
Code:
create table batch(
id BIGINT not null,
name VARCHAR(255),
primary key (id)
)
create table batchlot (
batch_id BIGINT not null,
lot_id BIGINT not null,
quantity INTEGER,
primary key (batch_id),
primary key (lot_id)
)
create table lot(
id BIGINT not null,
name VARCHAR(255),
primary key (id)
)
There are 3 classes corresponding to the tables. Batch, Lot and BatchLot. Batch has no attribut that link to lot, either database id or object reference.
Lot has no attribut that link to batch, either database id or object reference.
BatchLot has 2 attribut id, one for a batch and one for lot, and a quantity attribut.
Something like:
Code:
class batch
{
int id;
String name;
// ...
}
class lot
{
int id;
String name;
// ...
}
class batchlot
{
int batch_id;
int lot_id;
int quantity;
}
So there's a many-to-many relationship between batch and lots.
I thought adding a List of Lot in Batch and a List of Batch in Lot, using the batchlot table. But in this case what become the quantity attribut of the batchlot table ?
Should i create 3 mapping files :
batch.hbm.xml : a one-to-many to batchlotcorrel
batchlotcorrel.hbm.xml: a many-to-one to batch and a many-to-one to lot
lot.hbm.xml: a one-to-many to batchlotcorrel
and so adding a list of batchlotcorrel in batch and lot, and replacing batch id and lot id by reference on batch and lot objects ?
what do you think of this ?