For example, I have an entity
public class Foo { private String col1; private String col2; private String col3; private String col4;
I want to do select only col3 and col4 . But I already have a Foo constructor, as shown below:
public Foo (String col1, String col2) { this.col1 = col1; this.col2 = col2; }
Thus, I cannot have another constructor for col3 and col4 , because it will have the same signature.
What I'm trying to do so far is to create a complete constructor, for example:
public Foo (String col1, String col2, String col3, String col4) { this.col1 = col1; this.col2 = col2; this.col3 = col3; this.col4 = col4; }
But when I try to do something like below in my request
SELECT new Foo(null, null, f.col3, f.col4) FROM Foo f
I get
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected end of subtree
Although trying
SELECT new Foo(f.col1, f.col2, f.col3, f.col4) FROM Foo f
It works as expected.
EDIT:
I tried
Select f.col3, col4..
and the error below has been reset
org.springframework.dao.InvalidDataAccessApiUsageException: Cannot create TypedQuery for query with more than one return using requested result type [com.lala.entity.Foo]; nested exception is java.lang.IllegalArgumentException: Cannot create TypedQuery for query with more than one return using requested result type [com.lala.entity.Foo]