How to load an entity by a key other than primary key?
- by stacker
In a customized servlet (seam 2.1.2) this works fine
TableNameHome tableNameHome = (TableNameHome) Component.getInstance( "tableNameHome " );
tableName entity = tableNameHome.getInstance();
entity.setXXX();
tableNameHome.persit();
However this one fails:
entityManager = tableNameHome .getEntityManager();
Query query = entityManager.createQuery( "SELECT b FROM tablename b WHERE b.box_id = :key2nd" );
query.setParameter( "key2nd", value);
List results = query.getResultList();
and leads to this error message:
org.hibernate.hql.ast.QuerySyntaxException: tablename is not mapped
[SELECT b FROM tablename b WHERE b.key2nd = :key2nd]
In EJB 2.1 I could implement other finder-methods.
EntityHome.find() searches only by primary key.
What do I need to do in order to query by a different criteria than primary key?