【发布时间】:2014-10-23 12:02:00
【问题描述】:
我正在开发一个肥皂网络服务。我将 JPA 与 namedquery 注释一起用于数据查询。但是,在我的查询中将 sum 之类的聚合函数与 group by 结合使用会导致一些异常。我的代码如下所示。
@Entity
@Cacheable(false)
@Table(name = "criteriatable")
@XmlRootElement
@NamedQueries(
{
@NamedQuery(name = "Criteriatable.findAll", query = "SELECT c FROM Criteriatable c"),
@NamedQuery(name = "Criteriatable.findById", query = "SELECT c FROM Criteriatable c WHERE c.id = :id"),
@NamedQuery(name = "Criteriatable.findByCriteriaid", query = "SELECT c FROM Criteriatable c WHERE c.criteriaid = :criteriaid"),
@NamedQuery(name = "Criteriatable.findBySubcriteriaid", query = "SELECT c FROM Criteriatable c WHERE c.subcriteriaid = :subcriteriaid"),
@NamedQuery(name = "Criteriatable.findByProjectid", query = "SELECT c FROM Criteriatable c WHERE c.projectid = :projectid"),
@NamedQuery(name = "Criteriatable.findAllCriteriatableGroup", query = "SELECT c.criteriagroupname AS groupname, SUM(c.weight) AS groupweight FROM Criteriatable c WHERE c.projectid = :projectid GROUP BY c.criteriagroupname"),
@NamedQuery(name = "Criteriatable.SumAllWeightByProjectid", query = "SELECT SUM(c.weight) AS TotalProjectWeight FROM Criteriatable c WHERE c.projectid = :projectid")
})
public class Criteriatable implements Serializable
{
@Basic(optional = false)
@NotNull
@Column(name = "weight")
private double weight;
@Basic(optional = false)
@NotNull
@Column(name = "status")
private int status;
@Basic(optional = false)
@NotNull
@Lob
@Size(min = 1, max = 65535)
@Column(name = "criteriagroupname")
WS方法
@WebMethod(operationName = "getAllCriteriaGroupByProjectid")
public List<Criteriatable> getAllCriteriaGroupByProjectid(@WebParam(name = "projectid") int projectid)
{
EntityManager em = emf.createEntityManager();
String find = "Criteriatable.findAllCriteriatableGroup";
TypedQuery<Criteriatable> query = em.createNamedQuery(find, Criteriatable.class);
query.setParameter("projectid", projectid);
return query.getResultList();
}
我收到的错误是:
SEVERE: Error occured
javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: class [Ljava.lang.Object; nor any of its super class is known to this context.
javax.xml.bind.JAXBException: class [Ljava.lang.Object; nor any of its super class is known to this context.]
我需要帮助。谢谢。
【问题讨论】:
标签: java xml web-services jpa soap