I've spent the last week figuring this out, ultimately I had one line that was wrong.
When you have the database set up, and the entity beans in an EJB project, how do you connect to the server to access or update data?
Prerequisites: You should have entity beans in an EJB Project that reference a database.
  1. You should have two classes set up in your EJB project: BusinessRules.java, BusinessRulesRemote.java (or whatever you chose to call them). These files have a special method to construction, follow the list below.
    1. Secondary click the EJB project and select New > Session Bean
    2. Enter the package and class name (I chose "session" and "BusinessRules")
    3. If you want to use a remote interface (best for scalability) you will need to select it. You may leave the local interface (best for performance) button checked or you may uncheck it, I unchecked it.
    4. Click finish.
  2. Edit your BusinessRules.java and BusinessRulesRemote.java class.
    1. Now you need to implement your business logic.
      @Stateless /*These business rules are stateless.*/
      public class BusinessRules implements BusinessRulesRemote { /*class header*/
      @PersistenceContext /*If you are using Java EE then you will need this to get the Persistent context*/
      EntityManager manager; /*The manager you'll be using*/
      
      public static final String REMOTEJNDINAME = BusinessRules.class.getSimpleName() + "/remote"; /*JNDI name so that the class can be found*/
      
      public BusinessRules() { //Default constructor
      }
Note: if you use @PersistenceUnit instead of @PersitenceContext it will not work.

You will need to have methods in the BusinessRules class in order to access your data. Here is an example of how to select a person using their primary key (continued from the code above):
public Person getPerson(String personId) {
 Person aPerson = manager.find(Person.class, personId);
 return aPerson;
}
After you do this you will just need to call an instance of your BusinessRules class (businessRules) and then call methods (e.g. businessRuless.getPerson("1");)
In order to get an Object Person as an entity from your database based on their username and password you will want to overload your method in BusinessRules (or just not use the former method since it isn't very practical) and write a query using EJB QL. Example (continued from code above):
public Person getPerson(String userid, String password) {
 Query q = manager.createQuery("select p from Person p where p.userid = :uid and p.password = :pass");
 q.setParameter("uid", userid);
 q.setParameter("pass", password);
 Person aPerson = (Person) q.getSingleResult();
 return aPerson;
}
Resources: Sun, Enterprise JavaBeans 3.0 5th Edition 2006 Bill Burke & Richard Monson-Haefel