情况是这样子的. 有两个类, 比如说Car和Tires.关系是:public class Car {
private String tireType; // 轮胎类型, 轮胎有不一样的类型时以最多的一个为准.
...
@OneToMany
...
private Set<Tire> tires;
}
public class Tire {
private String tireType; // 轮胎类型
@ManyToOne
private Car car;
}然后前台页面查询时, 可以输入轮胎类型进行查询. 查询结果应该为Car集合, 且结果应该为拥有任意轮胎符合查询条件的Car.
这个地方不知道怎么查询.求教.
hql或者DetachedCriteria方式.hibernate
private String tireType; // 轮胎类型, 轮胎有不一样的类型时以最多的一个为准.
...
@OneToMany
...
private Set<Tire> tires;
}
public class Tire {
private String tireType; // 轮胎类型
@ManyToOne
private Car car;
}然后前台页面查询时, 可以输入轮胎类型进行查询. 查询结果应该为Car集合, 且结果应该为拥有任意轮胎符合查询条件的Car.
这个地方不知道怎么查询.求教.
hql或者DetachedCriteria方式.hibernate
轮胎类型:<input name="tireType"/>
<input type="submit" value="查询"/>
</form>//dao层
public List<Car> searchByTire(String cType) {
String hql = "from Car where tireType=?";
Session session = getSession();//省略
Query query = session.createQuery(hql);
query.setString(0,cType);
return query.list();
}
我想问的更像这个样子:
from Car car where car.tires.tireType=?
我想问的更像这个样子:
from Car car where car.tires.tireType=?你配好关联关系这样就可以了啊
我想问的更像这个样子:
from Car car where car.tires.tireType=?你配好关联关系这样就可以了啊
hql可以这样写?
我想问的更像这个样子:
from Car car where car.tires.tireType=?你配好关联关系这样就可以了啊
hql可以这样写?当然可以,,hql 面向对象的编程语言,,就是这样子的。。