我有两个实体:
然而,我无法根据经销商 ID 检索记录。我尝试了许多不同的方法,但仍然抛出此异常:
Dealer:
Dealers
和 Makes
。 Dealers 拥有多个 Makes。我可以将记录作为这两个实体之间的一对多关系插入。然而,我无法根据经销商 ID 检索记录。我尝试了许多不同的方法,但仍然抛出此异常:
Property not found make(it is table) of : class name(full classname)
如果有人能给我提供一些提示,那将不胜感激。Dealer:
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.OneToMany;
import javax.persistence.JoinTable;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
@Entity
@Table(name = "dealer")
public class Dealer implements java.io.Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
public Dealer(){
}
public Dealer(String DealerName,String dealerPhno,Set makes){
this.dealerName=DealerName;
this.dealerphno=dealerPhno;
this.dealerMakes=makes;
}
public void setDealerMakes(Set<Make> dealerMakes) {
this.dealerMakes = dealerMakes;
}
@Id
@GeneratedValue
@Column(name = "dealer_id")
private long dealerId;
public long getDealerId() {
return dealerId;
}
public void setDealerId(long dealerId) {
this.dealerId = dealerId;
}
public String getDealerName() {
return dealerName;
}
public void setDealerName(String dealerName) {
this.dealerName = dealerName;
}
public String getDealerphno() {
return dealerphno;
}
public void setDealerphno(String dealerphno) {
this.dealerphno = dealerphno;
}
@Column(name = "dealer_name" ,unique=true, nullable = false, length=20)
private String dealerName;
@Column(name = "dealer_phno" , nullable = false, length=20)
private String dealerphno;
@OneToMany(cascade = CascadeType.ALL)
//@OneToMany(fetch=FetchType.EAGER)
@JoinColumn(name="dealer_id", nullable=false)
//@JoinTable(name = "dealer_make", joinColumns = { @JoinColumn(name = "dealer_id") }, inverseJoinColumns = { @JoinColumn(name = "make_id") })
private Set<Make> dealerMakes = new HashSet<Make>(0);
public Set<Make> getDealerMakes() {
return dealerMakes;
}
}
制作
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "make")
public class Make implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 2L;
public Make(){
}
public Make(String makeName,String modelName,String price){
this.makeName=makeName;
this.modelName=modelName;
this.price=price;
}
public long getMakeId() {
return makeId;
}
public void setMakeId(long makeId) {
this.makeId = makeId;
}
public String getMakeName() {
return makeName;
}
public void setMakeName(String makeName) {
this.makeName = makeName;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
@Id
@GeneratedValue
@Column(name = "make_id")
private long makeId;
@Column(name = "make_name" , nullable = false, length=8)
private String makeName;
@Column(name = "model_name" , nullable = false, length=8)
private String modelName;
@Column(name = "price" , nullable = false, length=8)
private String price;
}
我尝试过的查询:
Criteria dealer=sessionFactory.getCurrentSession().createCriteria(Dealer.class);
Criteria make=dealer.createCriteria(make);
make.add(Restrictions.gt("dealerId",new Long(dealerId)));
List<Dealer> results=dealer.list(); //throwing exception
我期望的输出结果:
Dealer_Id 经销商名称 电话号码
1 halal 074563485
Make 表中有以下记录:
make_id 品牌名称 价格 经销商_id
1 ford 3000美元 1
2 hyundai 2000美元 1
我希望得到经销商和品牌详情的结果。