I have a java method that returns an Optional<Long>
:
Optional<Long> findOptionalRelation(String a, String b)
In the implementation there is a nativeQuery that counts results in a database:
hqlBuilder.append("SELECT count(r.id)");
hqlBuilder.append(" FROM RELATION r");
hqlBuilder.append(" WHERE r.a = :a AND r.b = :b");
final Query<Long> query = this.getCurrentSession().createNativeQuery(finalQuery);
query.setParameter("a", a);
query.setParameter("b", b);
return query.uniqueResultOptional();
However, when I execute the method test, it returns an Optional<BigInteger>
instead of an Optional<Long>
.
After that, I did a test for myself with Optional<Long> longOpt = Optional.of(new BigInteger("0"));
which of course cannot be cast.
How can I have bypassed the method return without breaking the execution?
Edit: this is the debugger: