如题,将一个组件类Com作为一个实体类A的属性,并在配置文件中以<component>标签配置好了。
public class Com{
private int a;
private int b;
//getter setter ...
}Com com = new Com();
//com初始化
查询的时候,如下的hql语句不能执行
select a from A a where a.com = ?
query.setParameter(0,com);//setParameter方法本上好像就是只能绑定Hibernate Type对象
必须要这样子写
select a from A a where a.com.a = ? and a.com.b = ?
query.setParameter(0,com.getA()).setParameter(1,com.getB());只能这样吗?还是有什么方法按照第一种查询方式来搞?
public class Com{
private int a;
private int b;
//getter setter ...
}Com com = new Com();
//com初始化
查询的时候,如下的hql语句不能执行
select a from A a where a.com = ?
query.setParameter(0,com);//setParameter方法本上好像就是只能绑定Hibernate Type对象
必须要这样子写
select a from A a where a.com.a = ? and a.com.b = ?
query.setParameter(0,com.getA()).setParameter(1,com.getB());只能这样吗?还是有什么方法按照第一种查询方式来搞?
这么写
query.setParameter(0,com,Hibernate.OBJECT)的话就没有问题。但直接让Hibernate自己猜测时就出现问题,这是怎么回事呢?
哈哈,sry,例子说得比较简单了。A实体类可以是
class A {
Long id;
Com com;
//getter,setter...
}