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