我在客户端 mssql 数据库中有两个表。第一个是作业表 - 所以我创建了一个包含负载类型和负载重量以及所有这些东西的作业实体 - 工作正常。
我现在的问题是有第二个表,其中包含有关装载和卸载点的信息。第二个表,我称之为 JEP,有一个由几个项目组成的主键:类型(加载或卸载)、邮政编码和客户编号。
我创建了一个实体 JobEndPoint,NetBeans 还创建了一个表示包含所有这些字段的主键 JobEndPointPK 的对象。
我想将两个 JobEndPoint(loadPoint 和 unloadPoint)添加到我的 Job 实体中。我现在的问题是:如何在 Hibernate 中注释它?在我看来,这是一个@OneToOne 关系船。如果我可以指定一个像SELECT * FROM JEP WHERE type="load" AND customer_nr="123" AND zip_code="123
..." 这样的 SELECT 语句,那将是完美的。Hibernate 可以吗?
谢谢你的帮助!
问候,
马可
以下是实体:
@Entity
@Table(name = "Auftragsdaten", catalog = "...", schema = "dbo")
public class Job implements Comparable<Object>, Serializable {
private static final long serialVersionUID = 4285871251915951149L;
@Id
@Basic(optional = false)
@Column(name = "`id`", nullable = false)
int id;
@Column(name = "`AufNr`", nullable=false)
int jobId;
@Transient
List<Integer> jobsAdded;
@Column(name = "`Beladedatum`", nullable=false)
@Temporal(TemporalType.DATE)
Date loadDate;
@Column(name = "`Beladezeit`")
@Temporal(TemporalType.TIME)
Date loadTimeFrom;
@Transient
Date loadTimeTo;
@Column(name = "`Entladedatum`", nullable=false)
@Temporal(TemporalType.DATE)
Date unloadDate;
@Column(name = "`Entladezeit Beginn`")
@Temporal(TemporalType.TIME)
Date unloadTimeFrom;
@Column(name = "`Entladezeit Ende`")
@Temporal(TemporalType.TIME)
Date unloadTimeTo;
@Transient
List<JobEndPoint> froms;
@OneToOne
@JoinColumns ({
@JoinColumn(name="`Beladetyp`", referencedColumnName = "`Ladetyp`", insertable = false, updatable = false),
@JoinColumn(name="`AbsNr`", referencedColumnName = "`KundenNr`", insertable = false, updatable = false),
@JoinColumn(name="`Verkehrsart`", referencedColumnName = "`VerkArt`", insertable = false, updatable = false),
@JoinColumn(name="`von LKZ`", referencedColumnName = "`LKZ`", insertable = false, updatable = false),
@JoinColumn(name="`von PLZ`", referencedColumnName = "`PLZ`", insertable = false, updatable = false)
})
JobEndPoint fromPoint;
@Transient
JobEndPoint toPoint;
@Column(name = "`Verkehrsart`", length = 10, nullable=false)
@Enumerated
JobType type;
@Column(name = "`Anzahl Paletten CCG1`")
int numberCCG1;
@Column(name = "`Anzahl Paletten CCG2`")
int numberCCG2;
@Transient
int numberFullContainer;
@Transient
int numberEmptyContainer;
@Column(name = "`Anzahl Container`")
int numberContainer;
@Column(name = "`Anz Stellplätze`")
int numberUnits;
@Column(name = "`Bruttogewicht`", nullable=false)
int loadWeight;
@ManyToOne
@JoinColumn(name="`Kühlkennzeichen`")
CoolingCode coolingCode;
}
@Entity
@Table(name = "BES", catalog = "...", schema = "dbo")
public class JobEndPoint implements Serializable {
private static final long serialVersionUID = 1017986852824783744L;
@Id
protected JobEndPointPK jobEndPointPK;
(...)
}
@Embeddable
public class JobEndPointPK implements Serializable {
@Basic(optional = false)
@Column(name = "`Ladetyp`", nullable = false, length = 50)
@Enumerated
EndPointType type;
@Basic(optional = false)
@Column(name = "`KundenNr`", nullable = false)
int customerId;
@Basic(optional = false)
@Column(name = "`VerkArt`", nullable = false, length = 10)
@Enumerated
JobType jobType;
@Basic(optional = false)
@Column(name = "`LKZ`", nullable = false, length = 3)
String countryCode;
@Basic(optional = false)
@Column(name = "`PLZ`", nullable = false, length = 7)
String zipCode;
}