Bushra Saifi :
I have a table name group having fields id , name etc. but i only want to fetch id and name so for this i made a separate (data transfer object).
I wrote a database query to return the Data transfer object but i don't know why it is showing an error : syntax error at or near"."
@Query(value = "select new
com.colo.dashboard.api.dto.GroupNameDto(g.id, g.name) from groups
g", nativeQuery = true)
List<GroupNameDto> getGroupsName();
GroupNameDto:
public class GroupNameDto {
private Long id;
private String name;
public GroupNameDto(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}}
actual result: syntax error near or at .
Patel Romil :
@Entity
public class GroupName {
private Long id;
private String name;
public GroupName(Long id, String name) {
this.id = id;
this.name = name;
}
}
public class GroupNameDto {
private Long id;
private String name;
public GroupNameDto(Long id, String name) {
this.id = id;
this.name = name;
}
}
@Query(value="select new com.colo.dashboard.api.dto.GroupNameDto(g.id, g.name) from GroupName g")
List<GroupNameDto> getGroupsName();