Hibernate标准返回多个类

时间:2011-10-27 11:19:44

标签: hibernate criteria

我是Hibernate标准的新手,我遇到了简单获取类的问题。 假设我们有课程:

    Class A{
    int id;
    List<A> aList;
    }

  Class B{
    A a;
    (...)

}

和:

Class C{
int id;
String name;
B b;
}

我想获得List&lt; C>如果'name'喜欢'abc'。这是我的标准代码:

    Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
    Criteria crit = session.createCriteria(C.class);
    crit.add(Restrictions.like("nazwa", "%"+string+"%").ignoreCase());
    return crit.list();

我有例外:

  

org.postgresql.util.PSQLException:错误:运算符不存在:   字符变化=整数

在我通过条件生成的SQL查询中,我可以在我的C类中包含的A和B类中看到“左外连接”。可能这就是为什么我无法加载

1 个答案:

答案 0 :(得分:1)

如果关联为@OneToOne@ManyToOne,则会有左外连接,只是因为默认情况下他们非常渴望 ToOne 拥有方。

如果您想使用此类LIKE条款,请改为使用MatchMode.ANYWHEREilike

add(Restrictions.ilike("nazwa", string, MatchMode.ANYWHERE))

此外,请确保要在类C中查询的属性名为nazwa(在代码示例中键入为name),并且它具有正确的getter /设定器。

相关问题