openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dain Sundstrom <>
Subject Map based one-to-many
Date Tue, 12 Dec 2006 06:27:31 GMT
You new it was coming... so do Map based collections work?  :)

As many of you know, I'm trying to implement CMP2 on top of OpenJPA.   
To implement CMR collection sets, it would be very convenient to have  
a Map<PK, Bean> instead of just a Set<Bean>, so I was very pleased to  
see support for this in the JPA spec.

Unfortunately, when I have Map one-to-many field with a with a map- 
key, OpenJPA starts generating SQL for which include a join table.  I  
would have assumed that a Set<Bean> and a Map<PK, Bean> would  
generate the same sql with the only difference being that the latter  
would result in map.put(pk, bean).

Is my assumption wrong?  Is my mapping wrong?  (sorry about the lack  
of a readable data model)

   <entity name="OneToManyA"  
     <table name="OneToManyA"/>
       <id name="field1">
         <column name="A1"/>
       <basic name="field2">
         <column name="A2"/>
       <one-to-many name="b">
         <map-key name="field1"/>

   <entity name="OneToManyB"  
     <table name="OneToManyB"/>
       <id name="field1">
         <column name="B1"/>
       <basic name="field2">
         <column name="B2"/>
       <many-to-one name="a">
         <join-column name="FKA1"/>



View raw message