JPA エンティティを XML に変換するために、EclipseLink JPA および JAXB (MOXy) を使用しています。通常の 1 対多操作の場合、システムは正常に動作しますが、この関係が双方向で、エンティティの 1 つに複合 ID があり、java.util.Map クラスを使用している場合、システムは例外をスローします。
関係は次のとおりです。
表1:
Fields: id, col1.
Primary Key: id
表 2:
Fields: id, table1_id, col1
Primary Key: (id, table1_id)
私のクラス:
クラス表 1:
@Entity
@Table(name = "table1")
@XmlRootElement
public class Table1 implements Serializable {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "table1")
@MapKey(name = "table2PK")
@XmlElement
@XmlInverseReference(mappedBy="table1")
private Map<Table2PK, Table2> table2;
@XmlElementWrapper(name="table2s")
public Map<Table2PK, Table2> getTable2() {
return table2;
}
// Gettters and setters methods
}
クラス テーブル 2:
@Entity
@Table(name = "table2")
@XmlRootElement
public class Table2 implements Serializable {
@EmbeddedId
protected Table2PK table2PK;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "table1_id", insertable = false, unique = false, nullable = false, updatable = false)
private Table1 table1;
// Gettters and setters methods
}
クラス Table2PK:
@Embeddable
public class Table2PK implements Serializable {
@Basic(optional = false)
@Column(name = "id")
private int id;
@Basic(optional = false)
@Column(name = "table1_id")
private int table1Id;
// Gettters and setters methods
}
JPA は正常に動作しますが、JAXB は次のコードでマーシャリングおよびアンマーシャリング操作を行います。
JAXBContext jc1 = JAXBContext.newInstance(Table1.class);
Marshaller marshaller = jc2.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(ts, System.out);
javax.xml.bind.JAXBException がスローされます。
メッセージは次のとおりです。
Exception [EclipseLink-110] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Descriptor is missing for class [java.util.Map].
Mapping: org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping[table2]
Descriptor: XMLDescriptor(org.jbiowhpersistence.datasets.gene.gene.entities.Table1 --> [DatabaseTable(table1)])
Exception [EclipseLink-110] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Descriptor is missing for class [java.util.Map].
Mapping: org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping[table2]
Descriptor: XMLDescriptor(org.jbiowhpersistence.datasets.gene.gene.entities.Table1 --> [DatabaseTable(table1)])
私のクラス定義で何が間違っていますか? よろしくお願いいたします。