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" class="org.apache.openejb.test.entity.cmr.onetomany.ABean_JPA">
    <table name="OneToManyA"/>
    <attributes>
      <id name="field1">
        <column name="A1"/>
      </id>
      <basic name="field2">
        <column name="A2"/>
      </basic>
      <one-to-many name="b">
        <map-key name="field1"/>
      </one-to-many>
    </attributes>
  </entity>

<entity name="OneToManyB" class="org.apache.openejb.test.entity.cmr.onetomany.BBean_JPA">
    <table name="OneToManyB"/>
    <attributes>
      <id name="field1">
        <column name="B1"/>
      </id>
      <basic name="field2">
        <column name="B2"/>
      </basic>
      <many-to-one name="a">
        <join-column name="FKA1"/>
        <cascade>
          <cascade-all/>
        </cascade>
      </many-to-one>
    </attributes>
  </entity>

Thanks,

-dain

Reply via email to