I use the dropwizard framework for my APIs. I have a named query as shown below:
@NamedQuery(name = "com.myapp.entity.MyEntity.findByMatchId", query = "SELECT test.name, count(test) as count FROM MyEntity as test,Entity1 as d where test.drug=d.id and test.drug.id= :drugId group by test.name") })
I return the result of the function count(test)
as a name count
. Below is my Entity class:
@NamedQuery(name = "com.myapp.entity.MyEntity.findByMatchId", query = "SELECT test.name, count(test) as count FROM MyEntity as test,Entity1 as d where test.drug=d.id and test.drug.id= :drugId group by test.name") })
@Entity
@Table(name = "my_entity")
@NamedQueries({
@NamedQuery(name = "com.myapp.entity.MyEntity.findByMatchId", query = "SELECT test.name, count(test) as count FROM MyEntity as test,Entity1 as d where test.drug=d.id and test.drug.id= :drugId group by test.name") }))
public class MyEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private String name;
@JsonBackReference("drug_id")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "drug_id", nullable = false)
private Drug drug;
@Column(name = "timestamp", nullable = false)
private Date timestamp;
private Long count;
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;
}
public Drug getDrug() {
return drug;
}
public void setDrug(Drug drug) {
this.drug = drug;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
public SideEffectSeverity getSideEffectSeverity() {
return sideEffectSeverity;
}
public void setSideEffectSeverity(SideEffectSeverity sideEffectSeverity) {
this.sideEffectSeverity = sideEffectSeverity;
}
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
}
What can I do here to get the correct mapping to the value of the count function as count.
Why is my mapping not going right, do I need to give it some annotation?
source
share