Consider createAlias method. The docs says: associationPath - A dot-seperated property path. I do not understand what it is? Say that there are 2 tables - Customer (id, name) and Ortder (id, customer_id). Supose that Criteria is created for Customer entity - what association path should be?
Could somebody provide several examples for several situations, like left join, inner join and of course join with clause?
Suppose there are 2 Entities (not tables) Customer and Order mapped to the mentioned tables. Class Order has @ManyToOne reference to Customer. You try to search Orders and want to get all orders of a customer with name "Customer1".
Criteria cr=sessioncreateCriteria(Order.class)
.createAlias("customer", "c", JoinType.INNER_JOIN);
Thus you use "customer" field name of Order entity class and make it alias with name "c".
Then you can add your condition for the alias "c"
cr.add(Restrictions.eq("c.name", customerNameParameter);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With