Hello, I am both a middlegen and a hibernate beginner, so please be patient.
I am currently trying to reverse the following db relationship:
CREATE TABLE SECURITY_PERMISSION (
PERMISSION_ID NUMBER NOT NULL,
NAME VARCHAR2(20) NOT NULL,
DESCRIPTION VARCHAR2(256)
)
ALTER TABLE SECURITY_PERMISSION ADD (
PRIMARY KEY (PERMISSION_ID)
CREATE TABLE SECURITY_PERMISSION_ATTR
(
ATTR_NAME VARCHAR2(16),
ATTR_VALUE VARCHAR2(16) NOT NULL,
PERMISSION_ID NUMBER
)
ALTER TABLE SECURITY_PERMISSION_ATTR ADD (
CONSTRAINT SEC_PERM_PK PRIMARY KEY (PERMISSION_ID, ATTR_NAME)
ALTER TABLE SECURITY_PERMISSION_ATTR ADD (
CONSTRAINT SEC_PERM_ID_FK FOREIGN KEY (PERMISSION_ID)
REFERENCES SECURITY_PERMISSION (PERMISSION_ID));
This is a pattern we would like to use extensively on our schema in order to provide a bunch of entities with generic attributes. Reading the hibernate documentation I have had the idea that this kind of situation would best be managed with a map where the permission_id in security_permission_attr is the "key" column, and the ATTR_NAME is the index one. Such as in what follows:
<map name="attributes" table="SECURITY_PERMISSION_ATTR">
<key column="PERMISSION_ID"/>
<index column="ATTR_NAME" type="string"/>
<element column="ATTR_VALUE" type="string">
</map>
I have tried to do this with middlegen, but what I get is
<!-- bi-directional one-to-many association to SecurityPermissionAttr -->
<set
name="securityPermissionAttrs"
lazy="true"
inverse="true"
>
<meta attribute="field-description">
@hibernate.set
lazy="true"
inverse="true"
@hibernate.collection-key
column="PERMISSION_ID"
@hibernate.collection-one-to-many
class="it.esselunga.ecommerce.data.model.SecurityPermissionAttr"
</meta>
<key>
<column name="PERMISSION_ID" />
</key>
<one-to-many
class="it.esselunga.ecommerce.data.model.SecurityPermissionAttr"
/>
</set>
Now: my goal is to define the correct hibernate mappings over a schema which is currently being refined, so I could be able to propose changes to the schema. Is middlegen imposing "set" because "map" is the wrong way to do with that schema? If so, what could be the best version for that relationship?
I also took a peek at the .vm file, and it seems that "map" is not supported at all. The question is: would implementing that kind of thing be difficult (read: impossible for some reason with current middlegen implementation) or is something I can do myself? It seems to me that choosing between collection implementations should be an option attached to the relationship: is defining option dialogs at the relationship level possible in middlegen as it is at the table and field level?
Thanks,
Davide Baroncelli
|