You must code retrievals of your entity on your entity DAO API, not on the entity itself.
A singleton read method must return your entity API, and should specify that null will be returned if no matching entity instance is found:
/** * Reads the instance with the specified name. * * @param name * the name to find * @return the instance with the specified name, or null if not * found. */ public MyNewEntity readByName(final String name);
A search method (which can return zero, one or many instances) must return a collection of your entity API (typically a Set):
/** * Searches all the instances which have the specified type. * * @param type * the type to search for * @return all the instances which have the specified type, or an * empty set if none found. */ public Set<MyNewEntity> searchByType( final MYNEWENTITYTYPEEntry type);
Your method names must follow the naming standards for modeled entity operations.
Use entity APIs in preference to passing primary keys, e.g. do this:
/** * Searches all the instances belonging to the specified parent. * * @param myParentEntity * the parent to search for * @return all the instances belonging to the specified parent, or * an empty set if none found. */ public Set<MyNewEntity> searchByParent( final MyParentEntity myParentEntity);
not this:
/** ********** VERY VERY BAD - DO NOT DO THIS! ********** */ /** * Searches all the instances which have the specified parent ID. * * @param myParentEntityID * the parent ID to search for * @return all the instances which have the specified parent ID, * or an empty set if none found. */ public Set<MyNewEntity> searchByParentID( final Long myParentEntityID); /** ********** VERY VERY BAD - DO NOT DO THIS! ********** */