在hibernate中使用布尔字段获取值

在hibernate中使用布尔字段获取值,hibernate,hql,Hibernate,Hql,我正在使用postgres,我有一个表,如下所示 CREATE TABLE entity_transaction ( id bigint NOT NULL DEFAULT nextval('entity_transactionid_seq'::regclass), transaction_ref character varying(11) NOT NULL, transaction_type character varying(10) NOT

我正在使用postgres,我有一个表,如下所示

    CREATE TABLE entity_transaction
    (
      id bigint NOT NULL DEFAULT nextval('entity_transactionid_seq'::regclass),
      transaction_ref character varying(11) NOT NULL,
      transaction_type character varying(10) NOT NULL,
      is_remitted boolean DEFAULT false);
我为该表创建了一个模型类,如下所示

    @Entity
    @Table(name = "entity_transaction")
    public class Transaction implements Serializable {

        private static final long serialVersionUID = 1L;

        @Id
        @Column(name = "id")
        Long id;

        @Column(name = "transaction_ref")
        String transactionRef;

        @Column(name = "transaction_type")
        String transactionType;

        @Column(name = "is_remitted")
        Boolean isRemitted;
我只是尝试使用“isrEmissed”字段从该表中获取值,该字段为true或false。为此,我尝试以下查询

    @Repository(value = "collectionsRepositary")
    public class CollectionsRepositoryImpl implements CollectionsRepository {

        @Resource
        private SessionFactory sessionFactory;

        @Override
        public List<Transaction> getUnmatchedList() {
            Query query = createQuery("select t from Transaction where t.transactionType = 'c' and t.isRemitted is true");      
            return query.list();
        }

        public Query createQuery(String queryString) {
            return getSession().createQuery(queryString);
        }

        private Session getSession() {
            return sessionFactory.getCurrentSession();
        }
    }       
@Repository(value=“CollectionsRepository”)
公共类CollectionsRepositoryImpl实现CollectionsRepository{
@资源
私人会话工厂会话工厂;
@凌驾
公共列表GetUnmatchdList(){
Query Query=createQuery(“从事务中选择t,其中t.transactionType='c'且t.IsrQuery为true”);
返回query.list();
}
公共查询createQuery(字符串查询字符串){
返回getSession().createQuery(queryString);
}
私有会话getSession(){
返回sessionFactory.getCurrentSession();
}
}       
但我无法获取返回空列表的值。该表中有具有此布尔值和transactionType的可用数据

有人能给我一个正确的方法吗


提前谢谢,

对此不确定,但
是真的
听起来对我来说很特别。 我认为您的查询应该使用
=true

编辑:很抱歉,我没有看到,您的查询应该如下所示:

select t from Transaction t where t.transactionType = 'c' and t.isRemitted = true
与此相反:

select t from Transaction t.transactionType = 'c' and t.isRemitted is true

缺少的

检查生成的查询;Hibernate应该将
java.lang.Boolean
映射为位,并且PG
Boolean
可能不是位,而是类似(但不同)的类型(例如TINYINT)。

根据我的经验,我总是用一个微小的或自定义类型映射布尔字段;检查是否有。

好,那么
convertToCollectionsDTO
做什么呢。我想你在
@Repository(value=“collectionsrepository”)
中有一个输入错误,是不是应该是Repository?不是。。。它的另一个目的是。。。所以我不包括在这里。。我更新了问题。。请再看一看。。