Quote:
if i understand this correctly a has 3 references to b... maybe, hopefully, you have table_a{a_id, b1_id, b2_id, b3_id} and table_b {b_id}
At first I thought that it is essentially what you descrive, however, technically it is more like table_a{a_id, b_id, b1type_value, b2type_value, b3type_value} and table_b {b_id, btype_id, btype_value} where class A has the fields in table_A as well as three Sets of values loaded from B which would be sets of the valid values, respectively, for b1type_value, b2type_value, b3type_value.
Quote:
In this case you have 3 m:1 relations.
No because
b_id is not unique (not even with the type_id). There will be (at the moment) between 1 and 4 records with the same b_id and btype_id (which is what I want). I want a little set of B's for each b?_id field in table_A. I have 3 m:m relations.
Quote:
You can map that easily enough with three different get methods getB1() getB2() getB3(). I realize that this introduces repeating fields to your table, but I do not believe you can have m:m without a mapping without either a mapping table or repeating fields.
I already have the three getters for sets of B but I think now maybe we aren't thinking the same thing exactly...
Quote:
Please dont have table_a{a_id, b_id} where b_id holds, i.e. 1|3|5 as a value. If you do, remove that and simply have repeating fields.
Maybe that is what I have, I've been looking at this for so long I can't think straight anymore.
Quote:
This will create a nightmare for someone else.
Ha, ha, it's already done it for me. ;)
Quote:
Does that help?
Not really but I think we're making progress. Let me give my actual model as example because perhaps trying to make my question generic is confusing the issue.
I have a table which is a third level Map on a "worksheet" called worksheet_factor
Code:
worksheet_factor {
worksheet_factor_id INT NOT NULL,
worksheet_product_id INT NOT NULL,
cost_factor_id INT NOT NULL,
calculated_type SMALLINT NOT NULL,
cost_factor_value FLOAT NULL,
foreign_amount FLOAT NULL,
currency_type SMALLINT NOT NULL,
exchange_rate FLOAT NULL,
prorating_type SMALLINT NOT NULL
}
cost_factor {
cost_factor_id INT NOT NULL,
calculated_type SMALLINT NOT NULL,
currency_type SMALLINT NOT NULL,
prorating_type SMALLINT NOT NULL,
worksheet_level SMALLINT NOT NULL
}
cost_factor_description {
cost_factor_id INT NOT NULL,
locale CHAR(2) NOT NULL,
description VARCHAR(30) NOT NULL
}
cost_factor_values {
cost_factor_id INT NOT NULL,
type SMALLINT NOT NULL,
allowable_type SMALLINT NOT NULL
}
calculated_type {
calculated_type SMALLINT NOT NULL,
locale CHAR(2) NOT NULL,
description VARCHAR(20) NOT NULL
}
prorating_type {
prorating_type SMALLINT NOT NULL,
locale CHAR(2) NOT NULL,
description VARCHAR(20) NOT NULL
}
and similar for currency...
The
cost_factor table will never be accessed directly or mapped to by Hibernate, it has 18 records which will "never" change. It holds the default values for the 3 type fields. The
worksheet_factor table holds the live data that represents one of the 18 cost factors on a "worksheet" (remember I said this is three levels deep). When a new record in
worksheet_factor is created it is populated by default with the values in the
cost_factor table. Each
worksheet_factor instance has a unique id and it also has the id of the particular 1..18 record of
cost_factor that it represents.
The internationalized descriptions of the 18 possible
cost_factors are stored in the
cost_factor_description table and keyed by cost_factor_id and locale.
The three type fields (calculated_type, currency_type, and prorating_type) in
worksheet_factor (which get their defaults from the
cost_factor table) are allowed to be set only to one of the values found for their type (this is I think similar to what you called b_id = 1|3|5 but it's not the b_id field (a.k.a. cost_factor_id) it's the type) found in the
cost_factor_values table. The reason for loading the collection of allowed values is to populate select boxes on the JSP page with the values the user is allowed to choose from. Since I need to show the user a meaningful string name to go with the numbers behind the scenes I need to load the internationalized description from the respective
xxxxx_type table (cross referenced by the allowable_type field in
cost_factor_values).
I think now that I have had the opportunity to type through all of that that my problem lies in the fact that Hibernate would like my object model to match my data model (sorry for making such a generalising limiting statement) and that if I just make a "meaningless" placeholder object for the
cost_factor table and create a m:1 from
worksheet_factor to
cost_factor and map all the interesting stuff through it instead of trying to map it directly onto an instance of a worksheet factor it will work because all of the primary keys for everything that Hibernate is so set on using will suddenly line up.
Why can't I just specify a different field instead of the primary key though?