How to calculate average value from data JPA - play-framework

720 views
Skip to first unread message

Tns publicbox

unread,
May 21, 2011, 12:16:59 AM5/21/11
to play-framework
Hello

I'm new to both Play framework and Java web programming. I try to
create my app follow what Wayne wrote in his book but I am not find
how to get average value from my data.

Someone please give me some example to get average value from data in
table.

Thank you.
Tns


I try this code
...
Query q = em.createQuery("select avg(w.totalcost) from Workorder w");
Double actual = (Double) q.getSingleResult();
...

I got this error message
The file /app/controllers/Application.java could not be compiled.
Error raised is : Query cannot be resolved to a type
In /app/controllers/Application.java (around line 191)
189: public static void doRecalcwocost(Long woid) {
190:
191: Query q = em.createQuery("select avg(w.totalcost) from Workorder
w");
192: Double avgcost = (Double) q.getSingleResult();

What is wrong?

/* Work Order Class */
package models;
import java.util.*;
import javax.persistence.*;
import play.db.jpa.*;

@javax.persistence.Entity
public class Workorder extends play.db.jpa.Model {
public Date wodate;
public String refid;
public String wosubject;
public String wotype;
public Date starttime;
public Date finishtime;
public Float totalcost = 0.0F;
@Column(length=4096)
public String wodetail;
public String user;
}

--

Guillaume Bort

unread,
May 21, 2011, 6:11:49 AM5/21/11
to play-fr...@googlegroups.com
Import javax.persistence.Query in your scope.

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

Reply all
Reply to author
Forward
0 new messages