Reputation: 1
I am new to hibernate actually. Having problems to create criteria object of the sql query below. Would you please lead me ?
SELECT P1.*,O1.PROJECT_OID FROM POINTALL P1
LEFT JOIN
OPERATION_PLAN O1
ON P1.OID = O1.GEOVISION_POINT_OID;
Upvotes: 0
Views: 2485
Reputation: 4807
If your POINTALL and OPERATION_PLAN table are mapped than only criteria will work otherwise use HQL or SQL.
This is what you need to create
Criteria criteria = getSession().createCriteria(POINTALL.class,"P1");
ProjectionList projections = Projections.projectionList();
projections.add(Projections.property("P1.something"),"aliasName");
projections.add(Projections.property("P1.something"),"aliasName");
..
projections.add(Projections.property("O1.PROJECT_OID"),"PROJECT_OID");
criteria.createAlias("P1.OPERATION_PLAN","O1", Criteria.LEFT_JOIN);
criteria.setProjection(projections);
Upvotes: 1
Reputation: 4030
You need not create criteria. You can execute native SQL queries or even write the same query in HQL which is very similar to SQL.
Upvotes: 0