I'm working on a play framework application, where ebean is included. So I decided to give it a try. I have a model where I use the @Formula
annotation to fetch a sum into the enty like so:
@Entity
public class Note extends Model {
private static final long serialVersionUID = -2384288983980432586L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(insertable = false, updatable = false)
private Long id;
@Transient
@Formula(select = "case a.upvotes when null then 0 else a.upvotes end case", join = "left outer join (select v.note_id, count(*) as upvotes from notevote v where v.noteval > 0 group by v.note_id) as a on a.note_id = ${ta}.id")
private Integer upvotes;
....
This query compiles and everything seems to work except for the fact that the upvotes
field is always null. So I read somewhere that this field should be included whenever I query for something using the ebean.finder. So to get by id, I need to write:
Ebean.find(Note.class).select("id, upvotes").setId(id).findUnique();
Instead of
Ebean.find(Note.class).setId(id).findUnique();
The problem is that it does not matter what I write in the select part above, it is ignored.