-->
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: Field from chield table as a key of Map on many-to-many RS.
PostPosted: Wed Sep 26, 2007 2:07 pm 
Newbie

Joined: Wed Sep 26, 2007 1:15 pm
Posts: 1
Location: Rio de Janeiro
Hi,

I have a special requirement for a mapping that I can't found how to do after more than 10 hours of "Googling". I will try to explain here to see if anyone can help.

Quote:
I have these tables:

Image

What I would like to map to the objects as follow:

1- The first level class represents the first table "Equipment" what have one Map attribute that I need to use the OperationName as the key (here is the problem).

2- The second level class in the map, what represents the table "Operations", have a List o commands and command are mapped on another class (third). But here, I need to order the List according the field CommandOrder from the COMMANDS table. (It's ok if I need to move this field to the n:m table, but not the first one.)



Then, the main problem for me is the first item. What I can do to map the field from a chield table to be a key of the Map on a many-to-many relation?

Please, any help is welcome.

Thanks,
Luis Amaral.



Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


_________________
Luis Amaral


Top
 Profile  
 
 Post subject: field from child table as map key
PostPosted: Fri Nov 30, 2007 8:00 am 
Newbie

Joined: Fri Nov 16, 2007 10:42 am
Posts: 6
You can use the "formula" tag for selecting a secondary field as the map key from the child table. That is also my current solution.
However, I think this is not very efficient. If anyone has got a better solution I, please share thoughts.


Here's what I'd do (in class Equipment):
Code:
      <map name="operations" table="equipment_operation" cascade="none" lazy="false" fetch="subselect" >
         <key column="equipmentId" not-null="true" />
         <map-key type="string" formula="(select o.operationName from operations o where o.operationId = operationId )" />
         <many-to-many column="operationId" class="Operation" />
      </map>


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.