Session.get not by id by unique constraint

Hallo

Is there a possibility to get an object by unique constraint?

Example:
@Entity
@Table(name = “tickers”,
uniqueConstraints = { @UniqueConstraint( columnNames =
{ “exchange_id”, “pair” }) } )

// 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?

Many Thanks
Sascha

@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…

You can use Session#byMultipleNaturalIds(), see this chapter of Hibernate’s new introduction guide for an example.