Hi!
I tried to get an answer at several locations, so I think I have to spend a credit to get an answer here...maybe ;-).
Well, suggest I want to model a letterhead. In Java I would generate a class like:
class Letterhead {
private String title;
private String address; [Mr. or Mrs.]
private String name;
private String surname;
....gettter/setter....
}
I would create an DB scheme like:
table letterhead (
letterhead_id: int;
name:varchar
surname: varchar;
title_id: int;
address_id: int;
)
table address (
address_id: int;
label: varchar;
)
table title (
title_id: int;
label: varchar;
)
I do this, because I want to have a normalized scheme. I figured out, that it is possible to have a mapping with more classes than tables in Hibernate, but not a mapping between more tables than classes.
I like to have hibernate to fill the fields of my letterhead class with the corresponding labels form the underlining foreign key relation. In my previous project that was be done by the application logic.
I do not want to have a separate class for address or title, because I like to have my domain model 'small'. Most of the time the model is complex enough without these additional classes.
Is there a way to do the mapping with hibernate or have I to do it again with good old JDBC coding? Honestly I would hate the JDBC coding after I learned hibernate ;-).
Thanks,
Danny
|