11. Examples

Map mapping in OpenJPA uses the same principles you saw in collection mapping. The example below maps the Article.authors map according to the diagram above.

Example 7.25. String Key, Entity Value Map Mapping

package org.mag.pub;

import org.apache.openjpa.persistence.*;
import org.apache.openjpa.persistence.jdbc.*;

@DataStoreIdColumn(name="AID" columnDefinition="INTEGER64")
public class Author {

package org.mag;

public class Article {
    @Id private long id;

    @ContainerTable(name="ART_AUTHS", joinColumns=@XJoinColumn(name="ART_ID"))
    private Map<String,Author> authors;