Hibernate-Native SQL
1.标量(值)查询:
1 sess.createSQLQuery("SELECT * FROM CATS").list(); 2 sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").list();
1 sess.createSQLQuery("SELECT * FROM CATS") 2 .addScalar("ID", Hibernate.LONG) 3 .addScalar("NAME", Hibernate.STRING) 4 .addScalar("BIRTHDATE", Hibernate.DATE)
1 sess.createSQLQuery("SELECT * FROM CATS") 2 .addScalar("ID", Hibernate.LONG) 3 .addScalar("NAME") 4 .addScalar("BIRTHDATE")
2.实体查询:
1 sess.createSQLQuery("SELECT * FROM CATS").addEntity(Cat.class); 2 sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").addEntity(Cat.class);
1 sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE, DOG_ID FROM CATS").addEntity(Cat.class);