Mark Emerson
Mark Emerson

Reputation: 1

SQL Query to Hibernate Criteria

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

Answers (2)

commit
commit

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

Abhijith Nagarajan
Abhijith Nagarajan

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

Related Questions