I want to implement JPA query with INNER JOIN. I tried this:
@Override
public Optional<PaymentTransactions> paymentTransactionByWpfPaymentId(Integer id) {
String hql = "SELECT t.* FROM " + PaymentTransactions.class.getName() + " t "
+ " INNER JOIN " + WpfPaymentPaymentTransactions.class.getName() + " wppt "
+ " ON t.id = wppt.payment_transaction_id "
+ " WHERE wppt.wpf_payment_id = :id "
+ " ORDER BY t.id ASC LIMIT 1";
TypedQuery<PaymentTransactions> query = entityManager.createQuery(hql, PaymentTransactions.class).setParameter("id", id);
List<PaymentTransactions> wpfPayments = query.getResultList();
return wpfPayments.isEmpty() ? Optional.empty() : Optional.of(wpfPayments.get(0));
}
But I get this error when I run the code:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: expecting IDENT, found '*' near line 1, column 10 [SELECT t.* FROM org.datalis.plugin.entity.PaymentTransactions t INNER JOIN org.datalis.plugin.entity.WpfPaymentPaymentTransactions wppt ON t.id = wppt.payment_transaction_id WHERE wppt.wpf_payment_id = :id ORDER BY t.id ASC LIMIT 1]
Do you know how I can fix this issue and what's causing it?
Probably I need to implement Spring Repository and make native query?