0 Replies Latest reply on Dec 16, 2008 9:01 AM by Milo Milovanovic

    Ejb finder doesn't work

    Milo Milovanovic Newbie

      Can anyone help me with the problem I have with finder methods? In the following text I give relevant pieces of code. Finder findUserByUsername(),
      (or any other that returns Collection) when invoked returns null although the database tables are not empty. Finder findByUsername() causes the
      following exception thrown by Jboss: javax.ejb.ObjectNotFoundException: No such entity!

      Does anyone know why this happens? People tell me to check finders for errors, but it seems to me they're OK. Can it be that there's something
      missing in Jboss configuration? I am able to run other similar examples & applications on my computer without errors so all this is very confusing.

      Any ideas,please? I'm desperate. :-)

      servlet Login.java code:

      String username = request.getParameter("username");
      String password = request.getParameter("password");

      UserFacadeLocalHome userFacadeLocalHome = (UserFacadeLocalHome)EJBHomeFactory.getFactory().lookupLocalHome(UserFacadeLocalHome.class, "ejb/movieshop/UserFacadeLocal");
      UserFacadeLocal userFacadeLocal = userFacadeLocalHome.create();
      //user = userFacadeLocal.getUser(username, password);
      user = userFacadeLocal.getUserByUsername(username, password);
      userFacadeLocal.remove();

      session bean UserFacadeBean:

      public UserDTO getUserByUsername(String username, String password) {
      ...
      ctx = new InitialContext();
      userLocalHome = (UserLocalHome)ctx.lookup("ejb/movieshop/UserLocal");
      usersCollection = userLocalHome.findUserByUsername(username, password);
      ...


      public UserDTO getUser(String username, String password) {
      ...
      ctx = new InitialContext();
      userLocalHome = (UserLocalHome)ctx.lookup("ejb/movieshop/UserLocal");
      userLocal = userLocalHome.findByUsername(username, password);
      ...

      entity bean UserBean (xDoclet code):

      package ejb.entity;
      /**
      * @ejb.bean
      * cmp-version="2.x"
      * name="User"
      * type="CMP"
      * jndi-name="ejb/movieshop/User"
      * local-jndi-name="ejb/movieshop/UserLocal"
      * reentrant="false"
      *
      * @ejb.finder
      * signature="java.util.Collection findUserByUsername(java.lang.String username, java.lang.String password)"
      * query="SELECT OBJECT(a) FROM User a WHERE a.username = ?1 AND a.password = ?2"
      * method-intf="LocalHome"
      *
      * @ejb.finder
      * signature="ejb.entity.UserLocal findByUsername(java.lang.String username, java.lang.String password)"
      * query="SELECT OBJECT(a) FROM User a WHERE a.username = ?1 AND a.password = ?2"
      * method-intf="LocalHome"
      *
      * @ejb.persistence
      * table-name="User"
      *
      * @ejb.transaction
      * type="Required"
      *
      * @jboss.table-name
      * table-name="User"
      *
      * @jboss.create-table
      * create="true"
      *
      * @jboss.remove-table
      * remove="false"
      */
      public abstract class UserBean implements EntityBean {
      ...