Finding data using a JPA entity

You can use access beans to find data. However, if you have a customized JPA entity, there is no need to wrap it in an access bean. Instead, define a JPA DAO implementation that extends AbstractJPAEntityDaoImpl, which provides some useful methods you can use directly.

Finding data by primary key

The following code snippet demonstrates how to select using a primary key.

EntityDao socialAccountDao = new SocialAccountDaoImpl();
SocialAccount socialAccount = socialAccountDao.find(new Long(10001));

Finding data by using a JPA named query

The following code snippet demonstrates how to select using a named query.
  1. Define your named query in the JPA entity.
  2. Use the JPA DAO implementation to execute the query and get the result.
    EntityDao socialAccountDao = new SocialAccountDaoImpl();
            List socialAccountList = socialAccountDao.query("SocialAccount.getSocialAccountsByMemberId", memberId);