// obtain the current session object Session session = sessionFactory.getCurrentSession(); // create a new instance of the MyEntity class MyEntity entity = new MyEntity(); // save the entity to the database session.save(entity);
// obtain the current session object Session session = sessionFactory.getCurrentSession(); // create a query to retrieve all MyEntity objects Query query = session.createQuery("from MyEntity"); // execute the query and retrieve the results ListIn this example, we obtain the current session object from the SessionFactory and create a query to retrieve all MyEntity objects from the database. We then execute the query using the session object and retrieve the results. The org.hibernate.SessionFactory class is part of the Hibernate package library.entities = query.list();