-->
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.  [ 1 post ] 
Author Message
 Post subject: Using formula attribute for non-primary-key column map index
PostPosted: Thu Mar 15, 2007 3:12 am 
Newbie

Joined: Thu Mar 15, 2007 2:25 am
Posts: 6
Hi,

I am attempting to map a Portfolio class which contains a Map<String,Long> (securitySymbols, shares)

The 'legacy' data schema for this has three tables (of concern):

1) A Portfolio table with the following columns
- Portfolio_Id integer (PK)
- Name varchar(255)

2) A PortfolioHolding table with the following columns (notice the composite primary key)
- Portfolio_Id integer (PK)
- Security_Id integer (PK)
- Shares bigint

3) A Security table with the following columns
- Security_Id integer (PK)
- Symbol string
- Price double

The issue is that the the map in the Portfolio class is indexed by the Security table's Symbol column value (not Security_Id) , with the map value element being the Shares column from the PortfolioHolding table. I have mapped this using the following mapping:

Code:
<class name="com.sb.app.model.Portfolio" table="Portfolio">
     <id name="id" column="Portfolio_Id">
          <generator class="native"/>
     </id>
     <property name="name" column="Name"/>
     <map name="holdings" table="PortfolioHolding">
          <key column="Portfolio_Id"/>
           <map-key column="Security_Id" formula="(SELECT Symbol FROM Security WHERE Security.Security_Id = Security_Id)" type="string"/>
           <element column="Shares" type="long" />
     </map>
</class>


To test if what schema hibernate would support for this mapping, I generate database schema using SchemaExport, the PortfolioHolding table thats described has a composite primark key of (Portfolio_Id, Shares)! Which makes me think that it wouldn't persists properly.

Basically, I cannot get it to recognize/set the Security_Id column as the primary key of the PortfolioHolding table if I use the formula attribute, but i need to use the formula attribute to populate my map key with the security Symbol rather than the Security_Id.

I am using Hibernate 3.2.1 and Java5.

Any help would be appreciated, i get the feeling I may be missing something obvious.

Thanks,
Eric


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

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.