Im just learning Hibernate so this should be a good opportunity to earn some credits :)
My problem is as follows. I am trying to create mapping files for a hierarchical relationship. The basic idea is this. I have (0-N) accounts. Each account has (0-N) computers. Each computer has (0-N) connections. Pretty simple huh? Here's the catch.
I want the accounts table to have a generated primary key. No problem.
I want the computers table to have a generated (primary?) key which is unique to each account (FK?) but not to the table as a whole. An example table might be as follows:
Code:
Computers
+-----------------------------------
| account_id | computer_id | ... all_the_other_computer_columns
+-------------+---------------+---
| 1 | 1 |
+-------------+---------------+---
| 1 | 2 |
+-------------+---------------+---
| 1 | 3 |
+-------------+---------------+---
| 2 | 1 |
+-------------+---------------+---
And so on....
Likewise, I would like to have the connections table have a generated (primary?) key which is unique to the (account,machine) pair but not to the table as a whole. For example:
Code:
Connections
+-----------------------------------------------------
| account_id | computer_id | connection_id | ...
+-------------+---------------+---------------+-----
| 1 | 1 | 1 |
+-------------+---------------+---------------+-----
| 1 | 1 | 2 |
+-------------+---------------+---------------+-----
| 1 | 3 | 1 |
+-------------+---------------+---------------+-----
| 2 | 1 | 2 |
+-------------+---------------+---------------+-----
My question is, how do I set up the mapping files to handle this situation? I have searched through the forum, the online docs, and "Hibernate, A J2EE Developer's Guide" to no avail.
Clarification would be greatly appreciated. Also, feel free to make suggestions about my database schema if you think there is a better way to do it.