Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); Employee employee = session.get(Employee.class, 1L); transaction.commit(); session.close();
Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); Person person = session.get(Person.class, new PersonPK("John", "Doe")); transaction.commit(); session.close();In this example, we retrieve a Person object from the database using a composite primary key. The get() method takes an instance of the primary key class as its second argument. The org.hibernate.Session class is part of the Hibernate package library, which is a popular Object-Relational Mapping (ORM) framework for Java. Its full package name is org.hibernate.Session.