I have a table say
MyTable (myId,myStringCol1,myStringCol2,myStringCol3)
When Using
QUERY1
hibernateTemplate.find("SELECT new(myId,myStringCol1) from MyTable")
I am getting the MyTable Object and for this there should be one constructor in the MyTable class like this
MyTable{
MyTable(Integer id,String col1){
this.id = id;
this.col1 = col1;
}
}
But when in another method I am calling like this
QUERY2
hibernateTemplate.find("SELECT new(myId,myStringCol2) from MyTable") ///myStringCol2
Here, there also be one constructor, like above, but we can’t create the same signature constructor.
So when running the second query (QUERY2) I am getting the myStringCol2 values in col1
because of the first constructor.
So how can I solve this problem..
Waiting for the suggestions.
How about this:
And then:
Q1
Q2
Would be nice if you could pass null instead of ”, but AFAIK you can not, because there is a bug that prevents you from doing that: https://forum.hibernate.org/viewtopic.php?f=1&t=985612&start=0. So, you will have to use ”
Another option, inspired by Talha answer would be:
Then you can just write:
Q1
Q2