How to load an entity by a key other than primary key?
Posted
by stacker
on Stack Overflow
See other posts from Stack Overflow
or by stacker
Published on 2010-06-10T11:53:20Z
Indexed on
2010/06/10
12:03 UTC
Read the original article
Hit count: 179
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?
© Stack Overflow or respective owner