Skip to content
Advertisement

JPA query is throwing a ‘not found’ error for column that isn’t in query

I’m trying to call for only specific columns in my DB but the query is throwing an error saying that the next column is not found (even though it’s not in the query)

Is there a problem in the join that’s doin this? I’m a bit perplexed as to this problem.

JPA Query from ConnectionRequestRepository –

Service –

Controller –

ConnectionRequest Class –

}

Image of error

Advertisement

Answer

Since you are mapping your native query to entity object, hibernate finds out that is an entity object due to all these annotation and everything, it is checking if this object is in persistence context cache or not.

So, it doesn’t find it and creates one, but then it tries to map the resultset from your query to this entity object but at the time of mapping it doesn’t find all the columns to initialise the entity (notice here column is expected but if value is null it may work).

But, if all columns are provided it is able to map to entity object.

Let me give you this example, suppose I have this Car entity

and my repository method is this

Notice that tested is not there, so hibernate issue same error

But if I include tested

Hibernate does this

If you look further down, it will give something like this

And in this case it successfully converts.

Solution to your problem

So if you want to use entity to be returned, you would have to provide all fields, otherwise you can use interface projections or something this question suggests

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