Hi
I have written Hibernate Criteria that searches in table Transactions.
Why Hibernate has genereted SQL query with all those joins that are completely redundand ?
Hibernate version:
2.1
Code between sessionFactory.openSession() and session.close():
Code:
Criteria criteria = session.createCriteria(Transaction.class)
.add(Expression.le("statusRefreshTime", systemDate))
.add(Expression.in("txStatus",new Byte[] {new Byte (TransactionGatewayConstants.TX_STATUS_UNKNOWN),new Byte (TransactionGatewayConstants.TX_STATUS_PENDING)} ));
List transactions = criteria.list();
return transactions;
Name and version of the database you are using:
MySQL 4.1
The generated SQL (show_sql=true):
select this.transactionId as transact1_6_, this.bankTransactionId as bankTran2_6_, this.amount as amount6_, this.description as descript4_6_, this.errorCode as errorCode6_, this.created as created6_, this.chargebackFee as chargeba7_6_, this.txStatus as txStatus6_, this.tx3DsecureStatus as tx3Dsecu9_6_, this.statusRefreshTime as statusR10_6_, this.customerName as custome11_6_, this.customerEmail as custome12_6_, this.customerIP as customerIP6_, this.orderId as orderId6_, this.referenceId as referen15_6_, this.reverseReason as reverse16_6_, this.reverseDate as reverse17_6_, this.chargeback as chargeback6_, this.chargebackDate as chargeb19_6_, this.merchantNotification as merchan20_6_, this.accountId as accountId6_, this.bankId as bankId6_, this.merchantId as merchantId6_, this.currencyId as currencyId6_, account1_.accountId as accountId0_, account1_.site as site0_, account1_.merchantNotificationUrl as merchant3_0_, account1_.chargebackFee as chargeba4_0_, account1_.accountLimit as accountL5_0_, account1_.merchantId as merchantId0_, account1_.currencyId as currencyId0_, merchant2_.merchantId as merchantId1_, merchant2_.name as name1_, merchant2_.description as descript3_1_, merchant2_.passwd as passwd1_, currency3_.currencyId as currencyId2_, currency3_.description as descript2_2_, bank4_.bankId as bankId3_, bank4_.name as name3_, bank4_.description as descript3_3_, bank4_.bankLimit as bankLimit3_, bank4_.serverUrl as serverUrl3_, merchant5_.merchantId as merchantId4_, merchant5_.name as name4_, merchant5_.description as descript3_4_, merchant5_.passwd as passwd4_, currency6_.currencyId as currencyId5_, currency6_.description as descript2_5_ from transactions this left outer join accounts account1_ on this.accountId=account1_.accountId left outer join merchants merchant2_ on account1_.merchantId=merchant2_.merchantId left outer join currencies currency3_ on account1_.currencyId=currency3_.currencyId left outer join banks bank4_ on this.bankId=bank4_.bankId left outer join merchants merchant5_ on this.merchantId=merchant5_.merchantId left outer join currencies currency6_ on this.currencyId=currency6_.currencyId where this.statusRefreshTime<=? and this.txStatus in (?, ?)