Using Hibernate 2.1.3.
I have a table layout that is a little unconventional and need some help mapping it properly for Hibernate.
Here are the table definitions:
Code:
lang
lang_id (pk)
code
lang_asset
lang_asset_id (pk)
table_name
row_id (numeric, id of foreign table)
field_name
lang_id
text_asset
resource
resource_id
resource_type
resource_file
resource_id
file_size
[file_name]
[file_summary]
resource_book
resource_id
page_count
[author_bio]
(pseudo fields are shown in brackets)
Sample content:
Code:
lang
id code
1 USEN (US/English)
2 JPJA (Japanese)
resource
id type
1 file
2 book
3 file
resource_file
id file_size
1 1234
3 9012
resource_book
id page_count
2 567
lang_asset
id table_name row_id field_name lang_id text_asset
1 resource_file 1 file_name 1 abcd_usen.txt
2 resource_file 1 file_name 2 abcd_jpja.txt
3 resource_file 1 file_summary 1 summary in english
4 resource_file 1 file_summary 2 summary in japanese
5 resource_book 2 author_bio 1 author bio in english
6 resource_book 2 author_bio 2 author bio in japanese
7 resource_file 3 file_name 1 efgh_usen.txt
8 resource_file 3 file_name 2 efgh_jpja.txt
9 resource_file 3 file_summary 1 summary in english
10 resource_file 3 file_summary 2 summary in japanese
So here's what I'm looking for:
* mapping of eg.Resource to RESOURCE
* mapping of subclass eg.ResourceFile to RESOURCE/RESOURCE_FILE
* mapping of subclass eg.ResourceBook to RESOURCE/RESOURCE_BOOK
* Use of descriminator field RESOURCE_TYPE would determine subclass.
* declaration of getter/setters for pseudo fields for file and book subclasses.
And functionality similar to this:
Code:
Lang lang = new Lang(1); # english only
ResourceFile file = (ResourceFile)resourceDAO.loadLocalized(new Long(1), lang);
Long size = file.getFileSize();
String name = file.getFileName();
String summary = file.getFileSummary();
file.setLang(lang);
file.setFileName("something_usen.txt");
file.setFileSummary("Summary of file in english");
resourceDAO.saveOrUpdate(file);
// deletion would cascade into text_asset, deleting just
// the rows for that particular lanaguage
resourceDAO.deleteLocalized(file, lang);
// deletion would delete all text_assets for this resource
resourceDAO.delete(file);
Is that possible?