我正在尝试从“Execution”表中检索“Vulcano”表中的最后 5 个插入数据,我正在使用 EclipseLink,Facade 类目前调用此查询;
这是我正在使用的 Facade 类的一部分;
public ArrayList<ExecutionPOJO> getLatestsVulcanoExecutions() {
ArrayList<ExecutionPOJO> vulcanoExecutions = new ArrayList<ExecutionPOJO>();
//SELECT x FROM Magazine x order by x.title asc, x.price desc
**List<Execution> excutionVulcanoList = em.createQuery("select s from Execution s order by s.vulcano_idVulcanoID desc limit 2 ").getResultList();**
如果我使用上述查询,我会收到此错误:
Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing the query [select s from Execution s order by s.vulcano desc limit 2], line 1, column 50: syntax error at [limit].
Internal Exception: MismatchedTokenException(80!=-1)
但是,如果我删除限制标签,我会收到此错误;
Caused by: Exception [EclipseLink-8021] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Error compiling the query [select s from Execution s order by s.vulcano desc], line 1, column 36: invalid ORDER BY item [s.vulcano] of type [uk.ac.aston.tomtom.entity.Vulcano], expected expression of an orderable type.
.
@Entity
public class Execution implements Serializable {
...
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int idExecution;
@ManyToOne(targetEntity = Vulcano.class)
private Vulcano vulcano;
*//Few others @ManyToOne
//also @oneToMany*
public Vulcano getVulcano() {
return vulcano;
}
public void setVulcano(Vulcano vulcano) {
this.vulcano = vulcano;
}
//other getter and setter
}
这是另一个实体;
@Entity
public class Vulcano implements Serializable {
...
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int idVulcano;
@OneToMany(targetEntity=Execution.class, mappedBy="vulcano", cascade=CascadeType.ALL)
private List<Execution> executions;
public List<Execution> getExecutions() {
return executions;
}
public void setExecutions(List<Execution> executions) {
this.executions = executions;
}
//other getters and setters