Queries in native SQL by R4R Team

In the Hibernate we can express a query in SQL, using createSQLQuery() and let Hibernate manage the mapping from result sets to objects. we can use any time call session.connection() and use the JDBC Connection directly. When we use the Hibernate API, you must enclose SQL aliases in braces:

List cats = session.createSQLQuery("SELECT {student.*} FROM STUDENT {student} WHERE ROWNUM<10")
    .addEntity("student", Student.class)

List student = session.createSQLQuery("SELECT {student}.ID AS {student.id}, {student}.SEX AS {student.sex}, " + "{student}.MATE AS {student.mate}, {student}.SUBCLASS AS {student.class}, ... " + "FROM STUDENT {student} WHERE ROWNUM<10")
    .addEntity("student", Student.class)

SQL queries can contain named and positional parameters, just like Hibernate queries.
Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!