java - Using Select and where statement in Criteria -


i in process of replacing jdbc hibernate in web application. have learned don't have write sql queries in this. instead of this,criteria queries can me. these sql queries want convert hibernate using criteria not hql.

string getorgidquery = "select * user_details user_id= ?"; rsdeptname = stmt.executequery("select department_name department department_id ="+ deptid + ";"); string insertcreatecdcvaluesfirst = ("update user_details set user_name=?, organization_id=?, department_id=?, access_ctrl = ?, user_role=? user_id = ?;"); 

first off must map table pojos.

string getorgidquery = "select * user_details user_id= ?"; 

preceding code in hibernate following.

criteria criteria = session.createcriteria(user_details.class); criteria.add(restrictions.eq("user_id",youruserid)); list<user_details> list = criteria.list(); 

your second select query same preceding.

string insertcreatecdcvaluesfirst = ("update user_details set user_name=?, organization_id=?, department_id=?, access_ctrl = ?, user_role=? user_id = ?;"); 

with hibernate criteria update looks following:

user_details user_details = (user_detailes) session.get(user_details.class,youruserid); user_details.setuser_name(newusername); user_details.setorganization_id(neworganizationid); // other fields update goes here session.update(user_details); tx.commit(); 

i hope you.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -