当我将Netbeans项目部署到Glassfish服务器时,我目前遇到BUILD FAILED错误的问题。我从日志中得到以下错误:Netbeans - 由于组合主键导致的Glassfish服务器部署错误
异常说明:来自实体类[class entity.InstrumentExtRef]的注释元素[field instrument]上的@JoinColumns不完整。当源实体类使用复合主键时,必须使用@JoinColumns为每个连接列指定@JoinColumn。名称和referencedColumnName元素都必须在每个这样的@JoinColumn中指定。请参阅server.log以获取更多详细信息。
有问题的表是instrument_ext_ref,并具有以下字段的组合主键:instrument_id和instrument_code_type。
似乎有问题的实体类 - InstrumentExtRef - 具有以下声明和注释。
@EmbeddedId
protected InstrumentExtRefPK instrumentExtRefPK;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 16)
@Column(name = "reference")
private String reference;
@JoinColumn(name = "instrument_code_type", referencedColumnName = "code_type", insertable = false, updatable = false)
@ManyToOne(optional = false)
private InstrumentCodeType instrumentCodeType1;
@JoinColumn(name = "instrument_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Instrument instrument;
和含有@EmbeddedId细节(InstrumentExtRefPK)实体类看起来像这样:
@Embeddable
public class InstrumentExtRefPK implements Serializable {
@Basic(optional = false)
@NotNull
@Column(name = "instrument_id")
private int instrumentId;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 10)
@Column(name = "instrument_code_type")
private String instrumentCodeType;
类InstrumentCodeType是指具有一个主键code_type(被引用列)表instrument_code_type。类工具是指表格工具,其本身具有由列“id”(所引用的列)和列“exchange_exchange_code”组成的组合主键。
从错误消息中可以明显看出,InstrumentExtRef实体中的复合主键是问题,但基于我对其他类似(但不完全相同)问题的研究,我认为我的实体类看起来不错。但我相对较新,可能会错过一些东西。