下面是与我面临问题的代码非常相似的相同代码
//mapped to Table B
class B implements Serializable {
//Primary key bId
private Long bId;
//Getter and setter for bId;
}
//Mapped to table C
class C implements Serializable {
//Primary key bId
private Long cId;
//Getter and setter for cId;
}
//mapped to Table A (Which has composite key fBid and fCid)
class A{
//Composite primary key
private B bid;
private C cid;
//getter and setter for B and C
//Other fields
}
如果我将创建如下标准:-
B b = new B();
b.setBId(1l);
C c = new C();
c.setCId(2l);
Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(A.class,"a");
criteria.add(Restrictions.eq("a.bid", b));
criteria.add(Restrictions.eq("a.cid",c));
A result = (A) criteria.uniqueResult();
return result;
我低于异常
org.postgresql.util.PSQLException:错误:运算符不存在:整数 = bytea
即使我创建了一个单独的类 BC,它具有 B 类和 C 类的对象,并在 A 类中使用它作为复合键。然后做了一个
Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(A.class,"a");
criteria.add(Restrictions.eq("a.BC", bc));
A result = (A) criteria.uniqueResult();
return result;
还是一样的错误
任何帮助将不胜感激。
注意:-我正在为所有类进行休眠 xml 映射。
我发现的解决方案更改了 A 类,如下所示:-
class A{
private BC bc;
//getter and setter
}
where BC
class BC{
private B b;
Private C c;
//getter and setters
}
Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(A.class,"a");
criteria.add(Restrictions.eq("bc.b", b));
criteria.add(Restrictions.eq("bc.c",c));
A result = (A) criteria.uniqueResult();
return result;