关于@OneToOne的问题
我的2个实体类定义为:@Entity
@Table(name = "Car")
public class Car {
private Long id;
private String plateKind;
private String plateNo;
private String tel;
private String phone;
private Date createtime;
private String tellKind;
private String flag;
private String type;
private BusinessSendTable businessSendTable;
@OneToOne(optional = false, cascade = CascadeType.ALL, fetch=FetchType.LAZY,mappedBy = "car")
public BusinessSendTable getBusinessSendTable() {
return businessSendTable;
}
public void setBusinessSendTable(BusinessSendTable businessSendTable) {
this.businessSendTable = businessSendTable;
}
@Column(name = "TYPE", length = 2)
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
// Property accessors
@Id
@GeneratedValue
@Column(name = "ID", unique = true, nullable = false, precision = 10, scale = 0)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "PLATEKIND", length = 20)
public String getPlateKind() {
return plateKind;
}
public void setPlateKind(String plateKind) {
this.plateKind = plateKind;
}
@Column(name = "PLATENO", nullable = false,length = 10)
public String getPlateNo() {
return plateNo;
}
public void setPlateNo(String plateNo) {
this.plateNo = plateNo;
}
@Column(name = "TEL", length = 20)
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
@Column(name = "PHONE",nullable = false, length = 20)
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Column(name = "TELLKIND", length = 50)
public String getTellKind() {
return tellKind;
}
public void setTellKind(String tellKind) {
this.tellKind = tellKind;
}
@Column(name = "FLAG", length = 2)
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name="CREATETIME", nullable=false, length=7)
public Date getCreatetime() {
return this.createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
}
@Entity
@Table(name = "BS_SMGW_SENDMESSAGE")
public class BusinessSendTable implements java.io.Serializable
{
private static final long serialVersionUID = -5421215988222802191L;
private Long id;//短信标识号
private Long detailId;//原始业务表id
private String receiver;//被叫号码
private String sender;//主叫号码
private String message;//短信内容
private String priority;//发送优先级
private Date createtime;//创建时间
private Date validtime;//有效时间
private Date attime;//定期发送时间
private String status;//发送状态
private String smgwId;//网关短信标识号
private Car car;
@OneToOne(optional = false, cascade = CascadeType.ALL)
@JoinColumn(name = "detailId", referencedColumnName = "id", unique = true)
public Car getCar() {
return car;
}
public void setCar(Car car) {
this.car = car;
}
/** default constructor */
public BusinessSendTable() {}
// Property accessors
@Id
@GeneratedValue
@Column(name = "ID", nullable = false, precision = 10, scale = 0)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "DETAILiD", precision = 10, scale = 0)
public Long getDetailId() {
return detailId;
}
public void setDetailId(Long detailId) {
this.detailId = detailId;
}
@Column(name = "RECEIVER", nullable = false, length = 21)
public String getReceiver() {
return this.receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
@Column(name = "SENDER", nullable = false, length = 21)
public String getSender() {
return this.sender;
}
public void setSender(String sender) {
this.sender = sender;
}
@Column(name = "MESSAGE", nullable = false, length = 1024)
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
@Column(name = "PRIORITY", length = 1)
public String getPriority() {
return this.priority;
}
public void setPriority(String priority) {
this.priority = priority;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATETIME", nullable = false, length = 7)
public Date getCreatetime() {
return this.createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "VALIDTIME", length = 17)
public Date getValidtime() {
return this.validtime;
}
public void setValidtime(Date validtime) {
this.validtime = validtime;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "ATTIME", length = 17)
public Date getAttime() {
return this.attime;
}
public void setAttime(Date attime) {
this.attime = attime;
}
@Column(name = "STATUS", length = 1)
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
@Column(name = "SMGWID", length = 200)
public String getSmgwId() {
return smgwId;
}
public void setSmgwId(String smgwId) {
this.smgwId = smgwId;
}
}
我写的HQL语句为select c.id,c.plateKind,c.plateNo,c.tel,c.phone,c.tellKind,c.flag from Car c left join c.businessSendTable b where c.id=b.detailId
可是最后生成的SQL语句却是select * from ( select car0_.ID as col_0_0_, car0_.PLATEKIND as col_1_0_, car0_.PLATENO as col_2_0_, car0_.TEL as col_3_0_, car0_.PHONE as col_4_0_, car0_.TELLKIND as col_5_0_, car0_.FLAG as col_6_0_ from Car car0_, BS_SMGW_SENDMESSAGE businessse1_ where car0_.ID=businessse1_.detailId(+) and car0_.ID=businessse1_.DETAILiD ) where rownum <= ?
导致查询出来的数据不对,请大侠告知这是什么原因啊??
--------------------编程问答-------------------- 眼睛都看瞎↓没用过 oneToOne ,
补充:Java , Java EE