-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: [middlegen]How to reverse a map instead of a set?
PostPosted: Wed Mar 03, 2004 9:15 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 10:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Middlegen always selects a Set only because it is value for both uni- and bi-directional associations. This way its does not have to check that the collection container is in the correct context. It also saved me adding an index selection feature etc.

I have been considering opening this up but it becomes a little messy and place further responcibility on the Middlegen user to correctly select the right options for the usage context.

You can edit the hibernate.vm velocity script which does the code generation to use a map if you wish. Alternatively, edit the resulting mapping document(s) by hand or use some automated process.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.