0

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; 

2 Answers 2

1

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); 
Sign up to request clarification or add additional context in comments.

4 Comments

then i get the following exception : org.hibernate.QueryException: could not resolve property: OPERATION_PLAN of: com.blabla.PointAll
Get the exact name which have you specified in PointAll bean for OPERATION_PLAN
pointAll is a view and operationPlan is a table. the only relation between them is pointOid. so no any relation with operationPlan in pointAll.
Than you can not use criteria api, try native sql or hql
0

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.

2 Comments

I am aware of HQL but i will need to add restrictions dynamically. that is my problem
If the two entities are related (or mapped), then you can do it via criteria else HQL is the way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.