// Open a session
Session session = sessionFactory.openSession();
// Begin a transaction
Transaction transaction = session.beginTransaction();
// Retrieve the object using the primary key
Ticker ticker = (Ticker) session.get(Ticker.class, “exchange_id”, “pair” );
This is not working! What is the easiest way to get a unique object by constraint?
@sappel you should try using Hibernate’s @NaturalId annotation, which identifies one or more properties which uniquely identify your entity instance, in combination with the org.hibernate.Session#byNaturalId method to use those properties when retrieving entities.
Many Thanks for the answer. Do you know a good example to retriving multi entities Update them and save back to the Database? I can’t find any example…