私は JPA と適切な注釈に多くの問題を抱えており、@JoinColumn、mappedBy などの多くの注釈と組み合わせを試しましたが、それでもエラーが発生します。私はEclipseLink(JPA 2.1)を使用しています。
私は所有者クラス Store を持っています:
@Entity
public class Store extends BaseEntity {
@NotNull
private String name;
@NotNull
@OneToMany
private List<Price> listPrices;
@NotNull
@OneToMany
private List<BusinessHours> listBusinessHours;
@NotNull
@OneToOne
@JoinColumn(name="store_id")
private PointCoordinates pointCoordinates;
...
}
これは PointCoordinates クラスです。
@Entity
public class PointCoordinates extends BaseEntity {
@NotNull
private float long;
@NotNull
private float lat;
@OneToOne(mappedBy="pointCoordinates")
private Store store;
...
}
これは「Store」の「@OneToMany」クラスの 1 つです。
@Entity
public class BusinessHours extends BaseEntity {
private Boolean holiday;
@ManyToOne
private Store store;
...
}
「Store」は「PointCoordinates」の所有者であるため、属性に注釈を付ける必要があり、反対側では属性に注釈を付ける必要があるため、機能するはずだと思いましたが、private Store store
それでも@OneToOne(mappedBy="pointCoordinates")
同じprivate PointCoordinates pointCoordinates
エラー@JoinColumn(name="store_id")
が発生します:
Glassfish 4.0 のエラー メッセージ
原因: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Fehler beim Zuweisen einer Verbindung. 原因: java.lang.IllegalStateException: Lokale Transaktion enthält bereits 1 Nicht-XA-Ressource: weitere Ressourcen können nicht hinzugefügt werden. エラー コード: 0 呼び出し: INSERT INTO POINTCOORDINATES (ID, LAT, LONG) VALUES (?, ?, ?) bind => [3 つのパラメーター バインド]
Glassfish 3.1.2.2 のエラー メッセージ (英語)
例外 [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Fehler beim Zuweisen einer Verbindung. 原因: java.lang.IllegalStateException: ローカル トランザクションには既に 1 つの非 XA リソースがあります: これ以上リソースを追加できません。エラー コード: 0 呼び出し: INSERT INTO POINTCOORDINATES (ID, LAT, LONG) VALUES (?, ?, ?) bind => [3 つのパラメーター バインド] クエリ: InsertObjectQuery(com.company.entities.output.rest.PointCoordinates@3a6a03ea)