I am having problems to implement a search in a PostgreSQl table. The table contains columns with empty strng values that causes an error.
Some information from the column design: Data type: character varying(20) Default: Not NULL: No Primary key: No
My java class annotation for the column: @Column(name = "codeClient") private String codeClient;
This query string works when there is no "empty string" value: SELECT c FROM Client c WHERE c.id = 765432
And my Json returns: [{"id":765432,"nameClient":"JACK SMITH","codeClient":"234567890"}]
When I change the query to deal with a empty value: SELECT c.id, c.nameClient, CASE c.codeClient WHEN '' THEN 'nonexistent' else c.codeClient END FROM Client c WHERE c.id = 765432
The query works, but the Json result misses de columns descriptions: [[765432,"JACK SMITH","234567890"]]
To solve this problem, I change the query to return an object: SELECT new ClientDTO(c.id, c.nameClient, CASE c.codeClient WHEN '' THEN 'nonexistent' else c.codeCliente END) FROM Client c WHERE c.id = 765432
But Hibernate can't solve when the result is an empty string: Java.lang.IllegalArgumentException: org.hibernate.QueryException: could not instatiate class [ClientDTO] from tuple
I've tried to use JPA CriteriaBuilder. It works on simple querys, but due to the complexity, I could not implement a query that I need.
I can't change de database design and I need the Json result.
Anybody can help me?
|