Hello, and thanks in advance for your time and assistance...
Synposis:
* Need a mapping for a hierarchical (recursive) relationship.
- Using hibernate 2.
- Hand-mapping the relationships absent from Middlegen-generated hbm's for an existing database.
Details:
The database schema tries to model a hierarchical relationship with a link table whose two columns are the parent and child id's, respectively. These id's are foreign keys to the entity primary key. For example, there is an Account entity with PK, AccountId. There is also an association table, AccountHierarchy, with columns ParentAccountId and ChildAccountId, each of which references AccountId (they "are" AccountId's).
If I was going top-down, I might have created a class Account not unlike the following:
class Account {
Account parent; // the parent Account
List children; // or whatever collection of child Accounts
...
}
Somehow I don't get the mapping I'm looking for with my (expanding) knowledge of hibernate. Other link tables were easy to map in the usual ways, for example, as bi-directional many-to-many's. So am I making too much out of this, in that I can't reason through how to implement this mapping?
Regards,
- James
P.S.
You all do great work that is appreciated, even by newbies such as myself!
|