我正在学习hibernate,我正在尝试检索要在数据表中显示的外键的值。我的实体类位于
之下Tbl事件
package Society;
// Generated 25-Oct-2017 07:05:34 by Hibernate Tools 4.3.1
> import java.util.Date; import java.util.HashSet; import java.util.Set;
> import javax.persistence.Entity; import
> javax.persistence.GeneratedValue; import
> javax.persistence.GenerationType; import javax.persistence.Id;
/**
* Tblevent generated by hbm2java
*/
@Entity
public class Tblevent implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer eventId;
private String eventName;
private String eventAddress1;
private String eventAddress2;
private String eventAddress3;
private String eventTown;
private String eventPostcode;
private String eventCountry;
private Date eventStartDate;
private Date eventEndDate;
private String eventDesc;
private Set<Tbleventattendees> tbleventattendeeses = new HashSet<Tbleventattendees>(0);
public Tblevent() {
}
public Tblevent(String eventName, String eventAddress1, String eventAddress2, String eventTown, String eventPostcode, String eventCountry, Date eventStartDate, Date eventEndDate, String eventDesc) {
this.eventName = eventName;
this.eventAddress1 = eventAddress1;
this.eventAddress2 = eventAddress2;
this.eventTown = eventTown;
this.eventPostcode = eventPostcode;
this.eventCountry = eventCountry;
this.eventStartDate = eventStartDate;
this.eventEndDate = eventEndDate;
this.eventDesc = eventDesc;
}
public Tblevent(String eventName, String eventAddress1, String eventAddress2, String eventAddress3, String eventTown, String eventPostcode, String eventCountry, Date eventStartDate, Date eventEndDate, String eventDesc, Set<Tbleventattendees> tbleventattendeeses) {
this.eventName = eventName;
this.eventAddress1 = eventAddress1;
this.eventAddress2 = eventAddress2;
this.eventAddress3 = eventAddress3;
this.eventTown = eventTown;
this.eventPostcode = eventPostcode;
this.eventCountry = eventCountry;
this.eventStartDate = eventStartDate;
this.eventEndDate = eventEndDate;
this.eventDesc = eventDesc;
this.tbleventattendeeses = tbleventattendeeses;
}
public Integer getEventId() {
return this.eventId;
}
public void setEventId(Integer eventId) {
this.eventId = eventId;
}
public String getEventName() {
return this.eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public String getEventAddress1() {
return this.eventAddress1;
}
public void setEventAddress1(String eventAddress1) {
this.eventAddress1 = eventAddress1;
}
public String getEventAddress2() {
return this.eventAddress2;
}
public void setEventAddress2(String eventAddress2) {
this.eventAddress2 = eventAddress2;
}
public String getEventAddress3() {
return this.eventAddress3;
}
public void setEventAddress3(String eventAddress3) {
this.eventAddress3 = eventAddress3;
}
public String getEventTown() {
return this.eventTown;
}
public void setEventTown(String eventTown) {
this.eventTown = eventTown;
}
public String getEventPostcode() {
return this.eventPostcode;
}
public void setEventPostcode(String eventPostcode) {
this.eventPostcode = eventPostcode;
}
public String getEventCountry() {
return this.eventCountry;
}
public void setEventCountry(String eventCountry) {
this.eventCountry = eventCountry;
}
public Date getEventStartDate() {
return this.eventStartDate;
}
public void setEventStartDate(Date eventStartDate) {
this.eventStartDate = eventStartDate;
}
public Date getEventEndDate() {
return this.eventEndDate;
}
public void setEventEndDate(Date eventEndDate) {
this.eventEndDate = eventEndDate;
}
public String getEventDesc() {
return this.eventDesc;
}
public void setEventDesc(String eventDesc) {
this.eventDesc = eventDesc;
}
public Set<Tbleventattendees> getTbleventattendeeses() {
return this.tbleventattendeeses;
}
public void setTbleventattendeeses(Set<Tbleventattendees> tbleventattendeeses) {
this.tbleventattendeeses = tbleventattendeeses;
}
}
Tblmembers
package Society;
// Generated 25-Oct-2017 07:05:34 by Hibernate Tools 4.3.1
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* Tblmembers generated by hbm2java
*/
@Entity
public class Tblmembers implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer memberId;
private String memberFirstName;
private String memberFamilyName;
private String memberPassword;
private String memberMiddleNames;
private String memberUserName;
private Set<Tbleventattendees> tbleventattendeeses = new HashSet<Tbleventattendees>(0);
public Tblmembers() {
}
public Tblmembers(String memberFirstName, String memberFamilyName, String memberPassword, String memberUserName) {
this.memberFirstName = memberFirstName;
this.memberFamilyName = memberFamilyName;
this.memberPassword = memberPassword;
this.memberUserName = memberUserName;
}
public Tblmembers(String memberFirstName, String memberFamilyName, String memberPassword, String memberMiddleNames, String memberUserName, Set<Tbleventattendees> tbleventattendeeses) {
this.memberFirstName = memberFirstName;
this.memberFamilyName = memberFamilyName;
this.memberPassword = memberPassword;
this.memberMiddleNames = memberMiddleNames;
this.memberUserName = memberUserName;
this.tbleventattendeeses = tbleventattendeeses;
}
public Integer getMemberId() {
return this.memberId;
}
public void setMemberId(Integer memberId) {
this.memberId = memberId;
}
public String getMemberFirstName() {
return this.memberFirstName;
}
public void setMemberFirstName(String memberFirstName) {
this.memberFirstName = memberFirstName;
}
public String getMemberFamilyName() {
return this.memberFamilyName;
}
public void setMemberFamilyName(String memberFamilyName) {
this.memberFamilyName = memberFamilyName;
}
public String getMemberPassword() {
return this.memberPassword;
}
public void setMemberPassword(String memberPassword) {
this.memberPassword = memberPassword;
}
public String getMemberMiddleNames() {
return this.memberMiddleNames;
}
public void setMemberMiddleNames(String memberMiddleNames) {
this.memberMiddleNames = memberMiddleNames;
}
public String getMemberUserName() {
return this.memberUserName;
}
public void setMemberUserName(String memberUserName) {
this.memberUserName = memberUserName;
}
public Set<Tbleventattendees> getTbleventattendeeses() {
return this.tbleventattendeeses;
}
public void setTbleventattendeeses(Set<Tbleventattendees> tbleventattendeeses) {
this.tbleventattendeeses = tbleventattendeeses;
}
}
tblEventAttendees
package Society;
// Generated 25-Oct-2017 07:05:34 by Hibernate Tools 4.3.1
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
/**
* Tbleventattendees generated by hbm2java
*
*/
@Entity
public class Tbleventattendees implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer eventAttendeeRecord;
@OneToMany
@JoinColumn(name = "eventId")
private Tblevent tblevent;
@OneToMany
private Tblmembers tblmembers;
private String memberComments;
public Tbleventattendees() {
}
public Tbleventattendees(Tblevent tblevent, Tblmembers tblmembers, String memberComments) {
this.tblevent = tblevent;
this.tblmembers = tblmembers;
this.memberComments = memberComments;
}
public Integer getEventAttendeeRecord() {
return this.eventAttendeeRecord;
}
public void setEventAttendeeRecord(Integer eventAttendeeRecord) {
this.eventAttendeeRecord = eventAttendeeRecord;
}
public Tblevent getTblevent() {
return this.tblevent;
}
public void setTblevent(Tblevent tblevent) {
this.tblevent = tblevent;
}
public Tblmembers getTblmembers() {
return this.tblmembers;
}
public void setTblmembers(Tblmembers tblmembers) {
this.tblmembers = tblmembers;
}
public String getMemberComments() {
return this.memberComments;
}
public void setMemberComments(String memberComments) {
this.memberComments = memberComments;
}
}
我正在运行以下Hibernate查询,它会带回正确的记录
来自Tbleventattendees a WHERE a.tblevent.eventId = 1
然而,显示的外围键值不是成员ID,它是对象的引用,例如Society.TblMembers.6a800ad6任何想法我怎么能带回外键值,即在数据库中的成员ID字段memberID中输入的值?
然后我尝试了以下内连接
来自Tbleventattendees的内部联接a.eventId但它告诉我这是一个无效的查询 感谢
理查德