1: import org.hibernate.HibernateException; 2: import org.hibernate.Query; 3: import org.hibernate.Session; 4: ... 5: public Object doInHibernate(Session session) throws HibernateException { 6: Query q = session.createQuery(b.toString()); 7: ... 8: return q.uniqueResult(); 9: }
1: sess = factory.openSession(); 2: Query q = sess.createQuery("select count(p) from Person p"); 3: ... 4: return ((Integer)q.uniqueResult()).intValue(); 5: } finally { 6: sess.close(); 7: }
1: 2: import org.hibernate.Query; 3: import org.hibernate.Session; 4: ... 5: tx = s.beginTransaction(); 6: Query q = s.createQuery( "select c from Client c where c.name = :name" ); 7: q.setString( "name", c.getName() ); 8: ... 9: c = (Client) q.uniqueResult(); 10: assertNotNull( c );
1: import org.hibernate.HibernateException; 2: import org.hibernate.Query; 3: import org.hibernate.Session; 4: ... 5: + " where name=?").setString(0, name) 6: .uniqueResult(); 7: } 8: ... 9: Session session = getSession(); 10: Query sqlQuery = session.createSQLQuery(hql).addEntity("p0", 11: ProjectDirectory.class); 12: ... 13: try { 14: ProjectDirectory pd = (ProjectDirectory) sqlQuery.uniqueResult();
1: import org.apache.log4j.PropertyConfigurator; 2: import org.hibernate.Query; 3: import org.hibernate.Session; 4: ... 5: .setMaxResults(1) 6: .uniqueResult() ; 7: tx.commit(); 8: ... 9: .createQuery(hqlQueryString).setMaxResults(1) 10: .uniqueResult(); 11: tx.commit(); 12: ... 13: .setMaxResults(1) 14: .uniqueResult() ;