1) Is there any reason you use SQL and not HQL which is objectoriented and much easier?
2)I hope this just a testMethod and you don't create a new SessionFactory (and Configuration) every time you call your other methods.
3)you should close the session at the end.
4) you should probably use a transaction
Code:
Transaction transaction = session.beginTransaction();
...
transaction.commit();
session.close();
5)named queries ("...where user_id=:id") are much more readable than indexed queries ("...where user_id=?")
6)-If you try to get the one instance of User with this user_id, use
Code:
User user = (User)session.get( User.class,tblObj.getUser_id() );
-If user_id is not the primary id but denotes an association and you want all Users associated with the instance with that id, use this HQL-Querry:
Code:
List<User> users = (List<User>)session.createQuery( "from User user where user.user_id=:user_id" )
.setString( "user_id",tblObj.getUser_id() )
.list();