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,
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.