Hi, I want to follow best practices of Hibernate, so I use surrogate keys in my tables as primary keys.
But when I want to retrieve objects from the db by business keys, I have to use a HQL query, which seems ugly to me when I want to retrieve it by a simple unique business key. Is there any other way to retrieve objects by business key?
Example:
Suppose you have a Cat class. Every cat has an surrogate id (primary key), and a unique name (business key).
Now you can get cat objects by using:
Code:
Cat cat = (Cat) sess.get(Cat.class, id);
But I want to get cat objects by business key. So I need the business key to be a temporary identifier for the query, while having the surrogate key as primary key.