Query query = session.createQuery("FROM Employee WHERE id = :employeeId"); query.setParameter("employeeId", 1L); Employee employee = (Employee) query.uniqueResult();
Query query = session.createQuery("SELECT COUNT(*) FROM Employee"); Long count = (Long) query.uniqueResult();This code executes a query to retrieve the number of Employee objects in the database and assigns the result to the count variable. Overall, the uniqueResult method is a valuable tool for retrieving a single, specific object from a database using Hibernate.