我在客戶端mssql數據庫中有兩個表。第一個是工作表 - 所以我創建了一個包含負載類型和負載重量以及所有這些東西的Job實體 - 工作正常。休眠MS SQL加入問題
我現在的問題是,有第二張表包含有關加載和卸載點的信息。第二張表,我稱之爲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?
感謝您的幫助!
Regeards,
馬爾科
這裏是實體:
@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;
}
謝謝!這看起來像一個開始。雖然我想要JobEndPoint對象,但Job對象中有JobEndPointPK是否正確?或者另一種方式:在運行時,如何獲得JobEndPointPK和JobEndPointPK存儲在作業中? – 2010-02-20 14:49:27
@Marco哎呀,我搞砸了:-(現在我更新了代碼,我還鏈接了一個更好的例子。 – 2010-02-20 21:41:16
@Marco沒有什麼明顯的...你能發佈你的最新代碼嗎? – 2010-02-22 14:44:57