Hi,
First, as a newbie in Hibernate, I'd like to thank all the people here - this is one of the best open-source sites I've seen - well documented and questions get answered quickly. I've been able to solve many issues with the initial setup and test without posting a single question.
I'm building an attachment handling module for my application that many entities contain a list of attachments (may be as large as 10MB or more). The module should implement upload/download functionalities using stream -> Blob conversion.
My first instinct is to map the attachments as a component collection of each entity because this can provide best performance (uploading attachments causes lock actions on the table).
But when I started to create the mapping, I realized that due to the way that Blobs are handled, I need to first create a persisted Attachment object with empty Blob content, then lock&upload and then associate it with its parent entity object.
Since many entities have attachments, it seemed impossible to map a single "Attachment" type to many "collection value" tables while letting Hibernating know which table should be used for a specific Attachment instance.
So an one-to-many relation mapping seems inevitable - which means that I'll have a single table for all attachments, with a structure like this:
TABLE ATTACHMENTS
COLUMN UNID PRIMARYKEY NUMBER
COLUMN PARENTUNID NUMBER
COLUMN FILENAME VARCHAR
COLUMN CONTENTTYPE VARCHAR
COLUMN CONTENT BLOB
What I'd like to be advised are:
1. Is my concern valid on using "value collection" type mapping? is it possible in Hibernate 2.1?
2. If I use the "one-to-many" type mapping and tread attachment as a independant entity, holding all attachments in a single table, will I get a performance hit when users upload attachments frequently?
Thanks in advance,
Dan
|