Skip to content
Advertisement

EntityManager createNativeQuery returning wrong result set in Java Springboot

I am stuck in this for half a day. My question may be scary with the image and JSon but my problem is not that difficult. I think I included all the information need for one to help. I have the following query

This query when run throught PgAdmin 4 returns this

enter image description here

But the JSon that I receive is this

I forgot to tell how I noticed the JSon is wrong. I should have a “link” with “studio-venda” and “link” with “loft-venda”.

Here is my Java code

Bellow is Imovel class

Advertisement

Answer

I was very fraightened by the bug I was having, because createNativeQuery was like a light in the end of the tunnel after struggling with the limitations of JpaRepository. After getting rid of nulls on the database column now the results are pretty much what I expect. I don’t know why my union with nulls running directly on the database works and with createNativeQuery it produces strange results. The particular column I was having problem is “descricao”, some table had null some have characters. I hope it can help others!

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement