「実行」テーブルから「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