This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.hibernate.Criteria; | |
| import org.hibernate.HibernateException; | |
| import org.hibernate.criterion.CriteriaQuery; | |
| import org.hibernate.criterion.Order; | |
| public class PostgisDistanceOrder extends Order { | |
| private boolean ascending; | |
| private String propertyName; | |
| private double fromLatitude; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT ... | |
| FROM ... | |
| WHERE ... | |
| ORDER BY ST_Distance(...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Criteria criteria = session.createCriteria(Programmer.class); | |
| criteria.add(Restrictions.sqlRestriction( | |
| "EXISTS(" + | |
| "SELECT pp.programmer_id " + | |
| "FROM programmers_projects pp " + | |
| "WHERE " + | |
| "pp.programmer_id = {alias}.programmer_id AND " + | |
| "pp.project_id IN (1, 2) )" | |
| )); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT pg.* | |
| FROM programmers pg | |
| WHERE EXISTS( | |
| SELECT pp.programmer_id | |
| FROM programmers_projects pp | |
| WHERE | |
| pp.programmer_id = pg.programmer_id AND | |
| pp.project_id IN (1, 2) -- or whatever condition to filter the projects | |
| ) |
NewerOlder