2

For defining criteria, I am using the below code piece

Conjunction c1 = Restrictions.conjunction();
c1.add(Restrictions.eq("owner", 123));
c1.add(Restrictions.eq("shared", 'N'));
c1.add(Restrictions.eq("cId", 20));

Conjunction c2 = Restrictions.conjunction();
c2.add(Restrictions.eq("shared", 'Y'));
c2.add(Restrictions.eq("cId", 20));

criteria.add(Restrictions.or(c1, c2));

Then, I want to fetch the unique results for this criteria.

CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
Projection originalProjection = criteriaImpl.getProjection();
ResultTransformer originalResultTransformer = criteriaImpl.getResultTransformer();
Object rowCount = criteria.setProjection(Projections.rowCount()).uniqueResult();

int rc = (Integer) rowCount;

However, the code fails at criteria.setProjection(Projections.rowCount()).uniqueResult() with an error printed on server logs like this below:

Info: forcing batcher resource cleanup on transaction completion; forgot to close ScrollableResults/Iterator?

And the exception that comes along is:

java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String

Any idea where I am going wrong?

2
  • That is Info message, what is the exception? Commented Mar 2, 2015 at 9:58
  • Added to the question, please check. ClassCastException it is. Commented Mar 2, 2015 at 10:02

1 Answer 1

3

It's probably this

c1.add(Restrictions.eq("shared", 'N'));

Try with this, in both places where you use it (" instead of ')

c1.add(Restrictions.eq("shared", "N"));
Sign up to request clarification or add additional context in comments.

2 Comments

To improve your answer you should mention why this change should be made and maybe in addition that the same counts for example ints and longs.
@Jan It was a character that I was passing to the restriction instead of a string. That was it! Thanks for asking clarification.

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.