I'm having some major difficulty in mapping a legacy data model without running into Exceptions and the like.
Here are my tables:
Code:
CREATE TABLE programs
(
program_id int NOT NULL,
/* other cols here */
PRIMARY KEY (program_id)
)
CREATE TABLE databases
(
program_id int NOT NULL,
database varchar(20) NOT NULL,
/* other cols here */
PRIMARY KEY (program_id, database),
FOREIGN KEY (program_id) REFERENCES programs(program_id)
)
CREATE TABLE db_tables
(
program_id int NOT NULL,
database varchar(20) NOT NULL,
table_name varchar(20) NOT NULL,
PRIMARY KEY (program_id, database, table_name),
FOREIGN KEY (program_id, database) REFERENCES databases(program_id, database)
)
I have created POJOs for the Program, Database, and Table types. There is a POJO for each composite key as well - DatabaseKey: int programId, String database & TableKey: DatabaseKey dbKey, String name . All classes implement Serializable and contain proper equals and hashcode implementations. I currently only require read-only access to the data. The Program class contains a Set of Database objects and the Database class contains a Set of Table objects (as indicated by the relational model). I only need unidirectional access from Program => Database => Table, but bidirectional would be a nicety.
Any suggestions?
I'll try and post the contents of my Java classes and mapping files shortly, but I don't have access to them at the moment.
Thanks a ton!