我在使用 JPA 和正确的注释时遇到了很多麻烦,并尝试了很多注释和组合,如 @JoinColumn、mappedBy 等,但仍然出现错误。我使用 EclipseLink (JPA 2.1)。
我有所有者类商店:
@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”类之一:
@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:异常 [EclipseLink-4002](Eclipse Persistence Services - 2.5.0.v20130507-3faac2b):org.eclipse.persistence.exceptions.DatabaseException 内部异常:java.sql.SQLException:Fehler beim Zuweisen einer Verbindung。Ursache: 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 内部异常: java.sql.SQLException: Fehler beim Zuweisen einer Verbindung。Ursache:java.lang.IllegalStateException:本地事务已经有 1 个非 XA 资源:无法添加更多资源。错误代码:0 调用:INSERT INTO POINTCOORDINATES (ID, LAT, LONG) VALUES (?, ?, ?) bind => [3 个参数绑定] 查询:InsertObjectQuery(com.company.entities.output.rest.PointCoordinates@3a6a03ea)