我正在使用旧式MS SQLServer表,在该表中,我试图联接两个在DB中没有任何关系且也没有主键的表。有一列 DealerRepCode 具有相同的值,我正在尝试利用此列来连接这些表。
下面是我的java类。您能告诉我我在做什么错吗?
实体类1
@Entity
@Table(name = "ADBAGENT1_CPS", schema = "dbo", catalog = "DB_Name")
public class Adbagent1Cps implements java.io.Serializable {
private Adbagent1CpsId id;
private Adbagent2Cps address;
public Adbagent1Cps() {
}
public Adbagent1Cps(Adbagent1CpsId id) {
this.id = id;
}
@EmbeddedId
@AttributeOverrides({ @AttributeOverride(name = "dealerRepCode", column = @Column(name = "DealerRepCode")),
@AttributeOverride(name = "agentName", column = @Column(name = "AgentName")),
@AttributeOverride(name = "phoneAreaCode", column = @Column(name = "PhoneAreaCode")),
@AttributeOverride(name = "phoneNumber", column = @Column(name = "PhoneNumber")),
@AttributeOverride(name = "phoneExtension", column = @Column(name = "PhoneExtension")),
@AttributeOverride(name = "faxAreaCode", column = @Column(name = "FaxAreaCode")),
@AttributeOverride(name = "faxNumber", column = @Column(name = "FaxNumber")),
@AttributeOverride(name = "cellAreaCode", column = @Column(name = "CellAreaCode")),
@AttributeOverride(name = "cellNumber", column = @Column(name = "CellNumber")),
@AttributeOverride(name = "inhouseAgent", column = @Column(name = "InhouseAgent")),
@AttributeOverride(name = "statementToAgent", column = @Column(name = "StatementToAgent")),
@AttributeOverride(name = "marketToClient", column = @Column(name = "MarketToClient")),
@AttributeOverride(name = "useDealerName", column = @Column(name = "UseDealerName")),
@AttributeOverride(name = "useDealerAddress", column = @Column(name = "UseDealerAddress")),
@AttributeOverride(name = "courierService", column = @Column(name = "CourierService")),
@AttributeOverride(name = "internalAgentId", column = @Column(name = "InternalAgentID")),
@AttributeOverride(name = "faxAgree", column = @Column(name = "FaxAgree")),
@AttributeOverride(name = "faxAgreeDate", column = @Column(name = "FaxAgreeDate")),
@AttributeOverride(name = "natlinkAgree", column = @Column(name = "NatlinkAgree")),
@AttributeOverride(name = "natlinkAgreeDate", column = @Column(name = "NatlinkAgreeDate")),
@AttributeOverride(name = "language", column = @Column(name = "Language")),
@AttributeOverride(name = "businessDevCode", column = @Column(name = "BusinessDevCode")),
@AttributeOverride(name = "agentEmail", column = @Column(name = "AgentEmail")),
@AttributeOverride(name = "agentEmailDateAdded", column = @Column(name = "AgentEmailDateAdded")),
@AttributeOverride(name = "agentEmailTimeAdded", column = @Column(name = "AgentEmailTimeAdded")),
@AttributeOverride(name = "agentEmailUserAdded", column = @Column(name = "AgentEmailUserAdded")),
@AttributeOverride(name = "programAdded", column = @Column(name = "ProgramAdded")),
@AttributeOverride(name = "agentStatus", column = @Column(name = "AgentStatus")),
@AttributeOverride(name = "statusDateChanged", column = @Column(name = "StatusDateChanged")),
@AttributeOverride(name = "statusTimeChanged", column = @Column(name = "StatusTimeChanged")),
@AttributeOverride(name = "statusUserChanged", column = @Column(name = "StatusUserChanged")),
@AttributeOverride(name = "futurUse", column = @Column(name = "FuturUse")) })
public Adbagent1CpsId getId() {
return this.id;
}
public void setId(Adbagent1CpsId id) {
this.id = id;
}
@OneToOne(mappedBy = "adbagent1Cps")
public Adbagent2Cps getddress() {
return address;
}
public void setAddress(Adbagent2Cps address) {
this.address = address;
}
}
实体类2
@Entity
@Table(name = "ADBAGENT2_CPS", schema = "dbo", catalog = "DB_Name")
public class Adbagent2Cps implements java.io.Serializable {
private Adbagent2CpsId id;
private Adbagent1Cps adbagent1Cps;
public Adbagent2Cps() {
}
public Adbagent2Cps(Adbagent2CpsId id) {
this.id = id;
}
@EmbeddedId
@AttributeOverrides({ @AttributeOverride(name = "dealerRepCode", column = @Column(name = "DealerRepCode")),
@AttributeOverride(name = "address1", column = @Column(name = "Address1")),
@AttributeOverride(name = "address2", column = @Column(name = "Address2")),
@AttributeOverride(name = "city", column = @Column(name = "City")),
@AttributeOverride(name = "postalCode", column = @Column(name = "PostalCode")),
@AttributeOverride(name = "provinceCode", column = @Column(name = "ProvinceCode")) })
public Adbagent2CpsId getId() {
return this.id;
}
public void setId(Adbagent2CpsId id) {
this.id = id;
}
@OneToOne()
@JoinColumns({
@JoinColumn(name = "DealerRepCode", insertable = false, updatable = false),
@JoinColumn(name = "AgentName", insertable = false, updatable = false),
@JoinColumn(name = "PhoneAreaCode", insertable = false, updatable = false),
@JoinColumn(name = "PhoneNumber", insertable = false, updatable = false),
@JoinColumn(name = "PhoneExtension", insertable = false, updatable = false),
@JoinColumn(name = "FaxAreaCode", insertable = false, updatable = false),
@JoinColumn(name = "FaxNumber", insertable = false, updatable = false),
@JoinColumn(name = "CellAreaCode", insertable = false, updatable = false),
@JoinColumn(name = "CellNumber", insertable = false, updatable = false),
@JoinColumn(name = "InhouseAgent", insertable = false, updatable = false),
@JoinColumn(name = "StatementToAgent", insertable = false, updatable = false),
@JoinColumn(name = "MarketToClient", insertable = false, updatable = false),
@JoinColumn(name = "UseDealerName", insertable = false, updatable = false),
@JoinColumn(name = "UseDealerAddress", insertable = false, updatable = false),
@JoinColumn(name = "CourierService", insertable = false, updatable = false),
@JoinColumn(name = "InternalAgentID", insertable = false, updatable = false),
@JoinColumn(name = "FaxAgree", insertable = false, updatable = false),
@JoinColumn(name = "FaxAgreeDate", insertable = false, updatable = false),
@JoinColumn(name = "NatlinkAgree", insertable = false, updatable = false),
@JoinColumn(name = "NatlinkAgreeDate", insertable = false, updatable = false),
@JoinColumn(name = "Language", insertable = false, updatable = false),
@JoinColumn(name = "BusinessDevCode", insertable = false, updatable = false),
@JoinColumn(name = "AgentEmail", insertable = false, updatable = false),
@JoinColumn(name = "AgentEmailDateAdded", insertable = false, updatable = false),
@JoinColumn(name = "AgentEmailTimeAdded", insertable = false, updatable = false),
@JoinColumn(name = "AgentEmailUserAdded", insertable = false, updatable = false),
@JoinColumn(name = "ProgramAdded", insertable = false, updatable = false),
@JoinColumn(name = "AgentStatus", insertable = false, updatable = false),
@JoinColumn(name = "StatusDateChanged", insertable = false, updatable = false),
@JoinColumn(name = "StatusTimeChanged", insertable = false, updatable = false),
@JoinColumn(name = "StatusUserChanged", insertable = false, updatable = false),
@JoinColumn(name = "FuturUse", insertable = false, updatable = false)
})
public Adbagent1Cps getAdbagent1Cps() {
return adbagent1Cps;
}
public void setAdbagent1Cps(Adbagent1Cps adbagent1Cps) {
this.adbagent1Cps = adbagent1Cps;
}
}
在尝试选择要进入休眠状态的某些数据时使用此映射正在执行以下2个查询,而第二个查询看起来不正确:
1- select TOP(@P0) adbagent1c0_.AgentEmail as AgentEma1_11_, adbagent1c0_.AgentEmailDateAdded as AgentEma2_11_, adbagent1c0_.AgentEmailTimeAdded as AgentEma3_11_, adbagent1c0_.AgentEmailUserAdded as AgentEma4_11_, adbagent1c0_.AgentName as AgentNam5_11_, adbagent1c0_.AgentStatus as AgentSta6_11_, adbagent1c0_.BusinessDevCode as Business7_11_, adbagent1c0_.CellAreaCode as CellArea8_11_, adbagent1c0_.CellNumber as CellNumb9_11_, adbagent1c0_.CourierService as Courier10_11_, adbagent1c0_.DealerRepCode as DealerR11_11_, adbagent1c0_.FaxAgree as FaxAgre12_11_, adbagent1c0_.FaxAgreeDate as FaxAgre13_11_, adbagent1c0_.FaxAreaCode as FaxArea14_11_, adbagent1c0_.FaxNumber as FaxNumb15_11_, adbagent1c0_.FuturUse as FuturUs16_11_, adbagent1c0_.InhouseAgent as Inhouse17_11_, adbagent1c0_.InternalAgentID as Interna18_11_, adbagent1c0_.Language as Languag19_11_, adbagent1c0_.MarketToClient as MarketT20_11_, adbagent1c0_.NatlinkAgree as Natlink21_11_, adbagent1c0_.NatlinkAgreeDate as Natlink22_11_, adbagent1c0_.PhoneAreaCode as PhoneAr23_11_, adbagent1c0_.PhoneExtension as PhoneEx24_11_, adbagent1c0_.PhoneNumber as PhoneNu25_11_, adbagent1c0_.ProgramAdded as Program26_11_, adbagent1c0_.StatementToAgent as Stateme27_11_, adbagent1c0_.StatusDateChanged as StatusD28_11_, adbagent1c0_.StatusTimeChanged as StatusT29_11_, adbagent1c0_.StatusUserChanged as StatusU30_11_, adbagent1c0_.UseDealerAddress as UseDeal31_11_, adbagent1c0_.UseDealerName as UseDeal32_11_ from B2BEMPowerdb_Refactor_Training.dbo.ADBAGENT1_CPS adbagent1c0_ where adbagent1c0_.AgentStatus=@P1
2- select adbagent2c0_.Address1 as Address1_12_1_, adbagent2c0_.Address2 as Address2_12_1_, adbagent2c0_.City as City3_12_1_, adbagent2c0_.DealerRepCode as DealerRe4_12_1_, adbagent2c0_.PostalCode as PostalCo5_12_1_, adbagent2c0_.ProvinceCode as Province6_12_1_, adbagent2c0_.AgentName as AgentNam7_12_1_, adbagent2c0_.PhoneAreaCode as PhoneAre8_12_1_, adbagent2c0_.PhoneNumber as PhoneNum9_12_1_, adbagent2c0_.PhoneExtension as PhoneEx10_12_1_, adbagent2c0_.FaxAreaCode as FaxArea11_12_1_, adbagent2c0_.FaxNumber as FaxNumb12_12_1_, adbagent2c0_.CellAreaCode as CellAre13_12_1_, adbagent2c0_.CellNumber as CellNum14_12_1_, adbagent2c0_.InhouseAgent as Inhouse15_12_1_, adbagent2c0_.StatementToAgent as Stateme16_12_1_, adbagent2c0_.MarketToClient as MarketT17_12_1_, adbagent2c0_.UseDealerName as UseDeal18_12_1_, adbagent2c0_.UseDealerAddress as UseDeal19_12_1_, adbagent2c0_.CourierService as Courier20_12_1_, adbagent2c0_.InternalAgentID as Interna21_12_1_, adbagent2c0_.FaxAgree as FaxAgre22_12_1_, adbagent2c0_.FaxAgreeDate as FaxAgre23_12_1_, adbagent2c0_.NatlinkAgree as Natlink24_12_1_, adbagent2c0_.NatlinkAgreeDate as Natlink25_12_1_, adbagent2c0_.Language as Languag26_12_1_, adbagent2c0_.BusinessDevCode as Busines27_12_1_, adbagent2c0_.AgentEmail as AgentEm28_12_1_, adbagent2c0_.AgentEmailDateAdded as AgentEm29_12_1_, adbagent2c0_.AgentEmailTimeAdded as AgentEm30_12_1_, adbagent2c0_.AgentEmailUserAdded as AgentEm31_12_1_, adbagent2c0_.ProgramAdded as Program32_12_1_, adbagent2c0_.AgentStatus as AgentSt33_12_1_, adbagent2c0_.StatusDateChanged as StatusD34_12_1_, adbagent2c0_.StatusTimeChanged as StatusT35_12_1_, adbagent2c0_.StatusUserChanged as StatusU36_12_1_, adbagent2c0_.FuturUse as FuturUs37_12_1_, adbagent1c1_.AgentEmail as AgentEma1_11_0_, adbagent1c1_.AgentEmailDateAdded as AgentEma2_11_0_, adbagent1c1_.AgentEmailTimeAdded as AgentEma3_11_0_, adbagent1c1_.AgentEmailUserAdded as AgentEma4_11_0_, adbagent1c1_.AgentName as AgentNam5_11_0_, adbagent1c1_.AgentStatus as AgentSta6_11_0_, adbagent1c1_.BusinessDevCode as Business7_11_0_, adbagent1c1_.CellAreaCode as CellArea8_11_0_, adbagent1c1_.CellNumber as CellNumb9_11_0_, adbagent1c1_.CourierService as Courier10_11_0_, adbagent1c1_.DealerRepCode as DealerR11_11_0_, adbagent1c1_.FaxAgree as FaxAgre12_11_0_, adbagent1c1_.FaxAgreeDate as FaxAgre13_11_0_, adbagent1c1_.FaxAreaCode as FaxArea14_11_0_, adbagent1c1_.FaxNumber as FaxNumb15_11_0_, adbagent1c1_.FuturUse as FuturUs16_11_0_, adbagent1c1_.InhouseAgent as Inhouse17_11_0_, adbagent1c1_.InternalAgentID as Interna18_11_0_, adbagent1c1_.Language as Languag19_11_0_, adbagent1c1_.MarketToClient as MarketT20_11_0_, adbagent1c1_.NatlinkAgree as Natlink21_11_0_, adbagent1c1_.NatlinkAgreeDate as Natlink22_11_0_, adbagent1c1_.PhoneAreaCode as PhoneAr23_11_0_, adbagent1c1_.PhoneExtension as PhoneEx24_11_0_, adbagent1c1_.PhoneNumber as PhoneNu25_11_0_, adbagent1c1_.ProgramAdded as Program26_11_0_, adbagent1c1_.StatementToAgent as Stateme27_11_0_, adbagent1c1_.StatusDateChanged as StatusD28_11_0_, adbagent1c1_.StatusTimeChanged as StatusT29_11_0_, adbagent1c1_.StatusUserChanged as StatusU30_11_0_, adbagent1c1_.UseDealerAddress as UseDeal31_11_0_, adbagent1c1_.UseDealerName as UseDeal32_11_0_ from B2BEMPowerdb_Refactor_Training.dbo.ADBAGENT2_CPS adbagent2c0_ left outer join B2BEMPowerdb_Refactor_Training.dbo.ADBAGENT1_CPS adbagent1c1_ on adbagent2c0_.DealerRepCode=adbagent1c1_.AgentEmail and adbagent2c0_.AgentName=adbagent1c1_.AgentEmailDateAdded and adbagent2c0_.PhoneAreaCode=adbagent1c1_.AgentEmailTimeAdded and adbagent2c0_.PhoneNumber=adbagent1c1_.AgentEmailUserAdded and adbagent2c0_.PhoneExtension=adbagent1c1_.AgentName and adbagent2c0_.FaxAreaCode=adbagent1c1_.AgentStatus and adbagent2c0_.FaxNumber=adbagent1c1_.BusinessDevCode and adbagent2c0_.CellAreaCode=adbagent1c1_.CellAreaCode and adbagent2c0_.CellNumber=adbagent1c1_.CellNumber and adbagent2c0_.InhouseAgent=adbagent1c1_.CourierService and adbagent2c0_.StatementToAgent=adbagent1c1_.DealerRepCode and adbagent2c0_.MarketToClient=adbagent1c1_.FaxAgree and adbagent2c0_.UseDealerName=adbagent1c1_.FaxAgreeDate and adbagent2c0_.UseDealerAddress=adbagent1c1_.FaxAreaCode and adbagent2c0_.CourierService=adbagent1c1_.FaxNumber and adbagent2c0_.InternalAgentID=adbagent1c1_.FuturUse and adbagent2c0_.FaxAgree=adbagent1c1_.InhouseAgent and adbagent2c0_.FaxAgreeDate=adbagent1c1_.InternalAgentID and adbagent2c0_.NatlinkAgree=adbagent1c1_.Language and adbagent2c0_.NatlinkAgreeDate=adbagent1c1_.MarketToClient and adbagent2c0_.Language=adbagent1c1_.NatlinkAgree and adbagent2c0_.BusinessDevCode=adbagent1c1_.NatlinkAgreeDate and adbagent2c0_.AgentEmail=adbagent1c1_.PhoneAreaCode and adbagent2c0_.AgentEmailDateAdded=adbagent1c1_.PhoneExtension and adbagent2c0_.AgentEmailTimeAdded=adbagent1c1_.PhoneNumber and adbagent2c0_.AgentEmailUserAdded=adbagent1c1_.ProgramAdded and adbagent2c0_.ProgramAdded=adbagent1c1_.StatementToAgent and adbagent2c0_.AgentStatus=adbagent1c1_.StatusDateChanged and adbagent2c0_.StatusDateChanged=adbagent1c1_.StatusTimeChanged and adbagent2c0_.StatusTimeChanged=adbagent1c1_.StatusUserChanged and adbagent2c0_.StatusUserChanged=adbagent1c1_.UseDealerAddress and adbagent2c0_.FuturUse=adbagent1c1_.UseDealerName where adbagent2c0_.DealerRepCode=? and adbagent2c0_.AgentName=? and adbagent2c0_.PhoneAreaCode=? and adbagent2c0_.PhoneNumber=? and adbagent2c0_.PhoneExtension=? and adbagent2c0_.FaxAreaCode=? and adbagent2c0_.FaxNumber=? and adbagent2c0_.CellAreaCode=? and adbagent2c0_.CellNumber=? and adbagent2c0_.InhouseAgent=? and adbagent2c0_.StatementToAgent=? and adbagent2c0_.MarketToClient=? and adbagent2c0_.UseDealerName=? and adbagent2c0_.UseDealerAddress=? and adbagent2c0_.CourierService=? and adbagent2c0_.InternalAgentID=? and adbagent2c0_.FaxAgree=? and adbagent2c0_.FaxAgreeDate=? and adbagent2c0_.NatlinkAgree=? and adbagent2c0_.NatlinkAgreeDate=? and adbagent2c0_.Language=? and adbagent2c0_.BusinessDevCode=? and adbagent2c0_.AgentEmail=? and adbagent2c0_.AgentEmailDateAdded=? and adbagent2c0_.AgentEmailTimeAdded=? and adbagent2c0_.AgentEmailUserAdded=? and adbagent2c0_.ProgramAdded=? and adbagent2c0_.AgentStatus=? and adbagent2c0_.StatusDateChanged=? and adbagent2c0_.StatusTimeChanged=? and adbagent2c0_.StatusUserChanged=? and adbagent2c0_.FuturUse=?