The beautiful thing about JPQL (or HQL) is the fact that you can use in your queries the properties of your Java class. You should not combine JPQL syntax with plain SQL syntax. You should replace pb.ITEM_REFERENCE_ID=:tcmURI
, pb.PUBLICATION_ID=:pubID
and pb.LAST_PUBLISHED_DATE
with pb.tcmuri=:tcmURI
, pb.publicationId=:pubID
and pb.last_published_date
. In addition to this, your parameter map should contain tcmURI and pubID instead of what you placed in there. Please note that I replaced the columns in the database with the actual fields from your entity. As a conclusion, your method should look something like this:
queryBuilder.append("select pa from PublishAction pa where pa.id in(select pb.id from PublishAction pb where pb.tcmuri=:tcmURI and pb.publicationId=:pubID and rownum <= 1 order by pb.last_published_date desc)");
Map<String, Object> queryParams = new HashMap<String, Object>();
queryParams.put("tcmURI", tcmURI);
queryParams.put("pubID", pubID);
Alternatively you can just split your query in 2 like this:
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("from PublishAction pb where pb.tcmuri=:tcmURI and pb.publicationId=:pubID order by pb.last_published_date desc");
Map<String, Object> queryParams = new HashMap<String, Object>();
queryParams.put("tcmuri", tcmURI);
queryParams.put("pubID", pubID);
final List<PublishAction> myActions = super.executeQueryListResult(queryBuilder.toString(), queryParams, 1);
if (myActions != null && !myActions.isEmpty()) {
StringBuilder queryBuilderFinal = new StringBuilder();
queryBuilderFinal.append("select pa from PublishAction pa where pa.id=:myId");
Map<String, Object> queryParamsFinal = new HashMap<String, Object>();
queryParamsFinal.put("myId", myActions.get(0).getId());
return super.executeQuerySingleResult(queryBuilderFinal.toString(), queryParamsFinal)
}
Note that I can only guess what are the names of the properties in your Java class so I just guessed that your have the tcmuri
, publicationId
and last_published_date
properties.
Hope this helps.