该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Cart 和Customer 两个类似一对一的关系
Cart类
@Entity(name="cart")
public class Cart {
private int id;
private Customer customer;
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@OneToOne
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
}
Customer:
@Entity(name="customer")
public class Customer {
private int id;
private String name;
private String password;
private int type;
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}
想这样删除Cart
hql="delete cart c where c.customer.name=?"
session.createQuery(hql).setParameter(0,customer.getName()).executeUpdate();
执行后报错:
Hibernate: delete from cart cross join customer customer1_ where name=?
ERROR: 关键字 'cross' 附近有语法错误。
org.hibernate.exception.SQLGrammarException: could not execute statement
求助