0

I have following problem: I am using Spring + Hibernate and am currently trying to select an id + amount of its id and return a list with each id and its corresponding amount. Now the problem is, that apperently the converter has a problem as I get following exception :

ConverterNotFoundException: No converter found capable of converting from type [java.lang.Long] to type [...entity.E_Amount]] with root cause

E_Amount creates Obejects with an id and an amount. And My Query:

 @Query("select t.e.id, count(t.id) from...")

returns a perfectly fine result of a long and an integer e.g. {9,101}

I am simply not completely sure how to start tackling this converting problem. Any ideas would be greatly appreciated!

1 Answer 1

1

Try the result class strategy:

1) Create a new class ResultClass with constructor accepting your query results:

public class ResultClass{

    public ResultClass(Integer id, Long count){..}
}

2) Amend the query a bit:

@Query("select new com.mypackage.ResultClass(t.e.id, count(t.id)) from...")
public List<ResultClass> query(..);

Just make sure that constructor arguments are in the same order as column in the select statement.

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

2 Comments

So basically as in my case E_Amount ? I tried it with select new com.*...*.E_Amount(...)) and now I received an IllegalArgumentException.
Ok so my current problem is that I actually have a spring/hibernate builder class for that object and therefore cant have a standard constructor , i think ? I am new to spring + hibernate so this is kinda confusing me. Anyway , my Server is giving me DetailedSemanticException as it cant locate an appropriate constroctur on class E_Amount ...

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.