JPA:几个关系

JPA:几个关系,jpa,eclipselink,one-to-many,one-to-one,many-to-one,Jpa,Eclipselink,One To Many,One To One,Many To One,我在JPA和正确的注释方面遇到了很多麻烦,并且尝试了很多注释和组合,比如@JoinColumn、mappedBy等等,但仍然会出错。我使用EclipseLink(JPA2.1) 我有一个所有者类商店: @Entity public class Store extends BaseEntity { @NotNull private String name; @NotNull @OneToMany private List<Price> lis

我在JPA和正确的注释方面遇到了很多麻烦,并且尝试了很多注释和组合,比如@JoinColumn、mappedBy等等,但仍然会出错。我使用EclipseLink(JPA2.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;
...
}
这是“商店”中的一个“@OneToMany”类:

@Entity
public class BusinessHours extends BaseEntity {

    private Boolean holiday;

    @ManyToOne
    private Store store;
    ...
}
我认为它应该会起作用,因为“Store”是“PointCoordinates”的所有者,所以我必须用
@OneToOne(mappedBy=“PointCoordinates”)
注释属性
private PointCoordinates PointCoordinates
,另一方面我必须用
@JoinColumn(name)注释属性
private PointCoordinates PointCoordinates
=“store_id”)
但我仍然收到相同的错误:

Glassfish 4.0上的错误消息

原因:javax.persistence.PersistenceException:异常 [EclipseLink-4002](Eclipse持久性服务)- 2.5.0.v20130507-3faac2b):org.eclipse.persistence.exceptions.DatabaseException Internal 异常:java.sql.SQLException:Fehler beim Zuweisen einer Ursache:java.lang.IllegalStateException:Lokale 第1项交易来源:weitere Resourcen können nicht hinzugefügt werden。错误代码:0调用:插入到 点坐标(ID、LAT、LONG)值(?,?)绑定=>[3 参数绑定]

Glassfish 3.1.2.2(英语)上的错误消息

异常[EclipseLink-4002](Eclipse持久性服务)- 2.3.2.v20111125-r10461):org.eclipse.persistence.exceptions.DatabaseException-Internal 异常:java.sql.SQLException:Fehler beim Zuweisen einer Ursache:java.lang.IllegalStateException:Local 事务已具有1个非XA资源:无法添加更多资源。 错误代码:0调用:插入点坐标(ID、LAT、LONG) 值(?,?)绑定=>[3个参数绑定]查询: InsertObjectQuery(com.company.entities.output.rest)。PointCoordinates@3a6a03ea)


我有答案!我得到这个错误是因为我用“@NotNull”注释了点坐标。这是错误的,你应该使用属性“optional”


我得到的另一个错误的原因是“本地事务已经有1个非XA资源:无法添加更多资源“发生这种情况是因为我有几个不同的事务和几个持久性单元。

如果您的环境有问题,这看起来像是一个问题。您使用的是应用服务器还是servlet容器?如果你认为你的JPA代码是这个异常的原因,试着解释一下这个关系。谢谢Michael的奉献,但是我解决了这个问题,看看我的答案。
@Entity
public class BusinessHours extends BaseEntity {

    private Boolean holiday;

    @ManyToOne
    private Store store;
    ...
}