OK. Although I can see that there are many "read"s to my question, I guess it is too dumb to deserve an effort to answer it ^_^
Anyway, I'd like to share the way I'll have to use. Any comment is welcome (I'm not so good in O/R mapping concepts, so my way of modeling the relations may not be good enough):
For each entity, a constant "entityType" attribute must be defined and used in the "where" attribute in the mapping for set "attachments". So that attachments can be filtered for a specific entity.
Also, the "entityType" must be hardcoded in the mapping due to be problem described in this thread:
http://forum.hibernate.org/viewtopic.php?t=928876&highlight=
Code:
(entity mapping)
<property name="entityType" type="string" ></property>
<map name="attachments" batch-size="1" cascade="delete-orphan"
inverse="true" where="parentType='this_entity_type_value'">
<key column="parentId"></key>
<index column="fileName" type="string" length="50"></index>
<one-to-many class="AttachmentInfo" /><!-- a light version that doesn't include the blob -->
</map>
(and attachment mapping)
<class name="AttachmentInfo" table="ATTACHMENTS">
<!-- properties mapping for super class -->
<id name="unid" column="unid" type="long" >
<generator class="sequence">
<param name="sequence">SEQ_ATTACHMENT</param>
</generator>
</id>
<version name="version" column="version" type="integer"
unsaved-value="undefined"></version>
<property name="fileName" length="50" />
<property name="contentType" length="50" />
<property name="parentId" type="long"></property>
<property name="parentType" type="string" ></property>
</class>
<!-- full version of attachments for download and insert -->
<class name="Attachment" table="HB_ATTACHMENTS">
<!-- properties mapping for super class -->
<id name="unid" column="unid" type="long" length="10">
<generator class="sequence">
<param name="sequence">SEQ_ATTACHMENT</param>
</generator>
</id>
<version name="version" column="version" type="integer"
unsaved-value="undefined"></version>
<property name="fileName" length="50" />
<property name="contentType" length="50" />
<property name="parentId" type="long"></property>
<property name="parentType" type="string" length="50"></property>
<property name="blob" type="blob" column="BLOB"></property>
</class>
The attachment is mapped in two different classes because I'd like to keep a non-lazy collection of summary of attachments with the entity. Attachment class is actually a subclass of AttachmentInfo.
regards,
Dan