3

I am using postgres and I have a table as follows,

    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);

I created a model class as follows for that table.

    @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;

I am just trying to get the values from that table using "isRemitted" filed is true or false. For this I am trying the following query

    @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();
        }
    }       

But I am unable to get the values, which was returning empty list. There is datas available in that table with this boolean value and transactionType.

Can anyone give me a right way in this?

thanks in advance,

2 Answers 2

3

Not sure about this but is true sounds special to me. I think your query should work with = true.

EDIT: I'm sorry, I didn't see that, your query should look like this:

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

instead of this:

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

The where is missing.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, so what does convertToCollectionsDTO do. And i think you have a typo in @Repository(value = "collectionsRepositary"), shouldn't it be Repository?
No... Its for other purpose... So I just not included here.. I updated the question.. Pls take a look again..
0

Check for generated query; Hibernate should maps java.lang.Boolean as BIT and probably a PG boolean is intendend not to be a BIT but a similar (but different) type (like a TINYINT, for example).
As my experience I have always mapped boolean fields with a tinyiny or a custom type; check on SO.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.