我有一个客户表和第二个反馈表。他们之间的Comman字段是CustomerId。我知道sql join查询,但我想在JSP中查询restful webservice。我写下这个代码,它抛出了内部服务器错误(500)。 我希望它需要一个自定义类,因为结果我们返回一个List<&gt ;.但我完全不知道。
@GET
@Path("/all")
@Produces({"application/json"})
public List<Feedback> find() {
return getEntityManager().createQuery("SELECT f.feedback,c.firstName FROM Feedback f INNERJOIN Customerdetail c on f.customerId=c.customerId")
.getResultList();
}
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing [SELECT f.feedback,c.firstName FROM Feedback f INNERJOIN Customerdetail c on f.customerId=c.customerId].
[46, 47] The FROM clause has 'Feedback f' and 'INNERJOIN Customerdetail' that are not separated by a comma.
[71, 72] The FROM clause has 'INNERJOIN Customerdetail' and 'c on' that are not separated by a comma.
[76, 77] The FROM clause has 'c on' and 'f.customerId=' that are not separated by a comma.
[89, 90] The FROM clause has 'f.customerId=' and 'c.customerId' that are not separated by a comma.
[74, 76] The identification variable 'on' cannot be a reserved word.
[89, 90] The identification variable '=' cannot be a reserved word.
[102, 102] An identification variable must be provided for a range variable declaration.
root cause
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [SELECT f.feedback,c.firstName FROM Feedback f INNERJOIN Customerdetail c on f.customerId=c.customerId].
[46, 47] The FROM clause has 'Feedback f' and 'INNERJOIN Customerdetail' that are not separated by a comma.
[71, 72] The FROM clause has 'INNERJOIN Customerdetail' and 'c on' that are not separated by a comma.
[76, 77] The FROM clause has 'c on' and 'f.customerId=' that are not separated by a comma.
[89, 90] The FROM clause has 'f.customerId=' and 'c.customerId' that are not separated by a comma.
[74, 76] The identification variable 'on' cannot be a reserved word.
[89, 90] The identification variable '=' cannot be a reserved word.
[102, 102] An identification variable must be provided for a range variable declaration.
答案 0 :(得分:1)
请在此处查看如何使用JPQL查询或使用Native查询。如果您向我们展示您的架构并描述您想要选择的内容,那么它也会很有帮助。 JPQL或本机查询: JPQL Querying
答案 1 :(得分:0)
您的查询中存在拼写错误:INNER JOIN
NOT INNERJOIN
。