私は自分のAPIにdropwizardフレームワークを使用しています。私は以下のように名前付きクエリを持っている:DAO SQL関数によって返されるフィールドをマップする方法は?
@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") })
私は名前count
としてcount(test)
関数の結果を返しています。以下は私のエンティティクラスである:
@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;
// This value is not getting mapped
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;
}
}
は、私が数としてカウント関数の値との正しいマッピングを取得するために、ここで何を行うことができます。
なぜマッピングが正しく行われないのですか。注釈を付ける必要はありますか?