I have much trouble with JPA and the right annotations and tried a lot of annotations and combinations like @JoinColumn, mappedBy and so on, but still get errors. I use EclipseLink (JPA 2.1).
I have the owner class 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;
...
}
This is the class PointCoordinates:
@Entity
public class PointCoordinates extends BaseEntity {
@NotNull
private float long;
@NotNull
private float lat;
@OneToOne(mappedBy="pointCoordinates")
private Store store;
...
}
And this is one of the "@OneToMany" classes of 'Store':
@Entity
public class BusinessHours extends BaseEntity {
private Boolean holiday;
@ManyToOne
private Store store;
...
}
I thought that it should work, because 'Store' is the owner of 'PointCoordinates' so I have to annotate the attribute private Store store
with @OneToOne(mappedBy="pointCoordinates")
and on the other side I have to annotate the attribute private PointCoordinates pointCoordinates
with @JoinColumn(name="store_id")
But I still get the same error:
Error message on Glassfish 4.0
Caused by: 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. Ursache: java.lang.IllegalStateException: Lokale
Transaktion enthält bereits 1 Nicht-XA-Ressource: weitere Ressourcen
können nicht hinzugefügt werden. Error Code: 0 Call: INSERT INTO
POINTCOORDINATES (ID, LAT, LONG) VALUES (?, ?, ?) bind => [3
parameters bound]
Error message on Glassfish 3.1.2.2 (English)
Exception [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. Ursache: java.lang.IllegalStateException: Local
transaction already has 1 non-XA Resource: cannot add more resources.
Error Code: 0 Call: INSERT INTO POINTCOORDINATES (ID, LAT, LONG)
VALUES (?, ?, ?) bind => [3 parameters bound] Query:
InsertObjectQuery(com.company.entities.output.rest.PointCoordinates@3a6a03ea)