0 Replies Latest reply on Oct 4, 2010 7:51 AM by Benjamin Mark

    Custom DAOs

    Benjamin Mark Newbie

      Hello,


      I'm quite new to seam. I'm used to work with JBoss MBeans.


      I generated a new project with seam-gen and now I try to build in a user query in the AuthenticatorBean to let login only people which are registered in the database. I used informations from that thread http://seamframework.org/Community/GenericDAOPatternWithSeammanagedTransactionsAndSMPCDoesntWork and now I'm getting the error


      Caused by: java.lang.NoClassDefFoundError: RegisterAction



      So the question is. Why is he missing RegisterAction and how can I fix it? Another question is Is this the right way to fetch the user table information from the mysql database?


      Thx for your help


      Ben



      AuthenticatorBean.java


      package ch.bemar.creditfriend.action;
      
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.ejb.Stateless;
      
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.security.Credentials;
      import org.jboss.seam.security.Identity;
      
      import ch.bemar.creditfriend.model.User;
      
      @Stateless
      @Name("authenticator")
      public class AuthenticatorBean implements Authenticator
      {
          @Logger
          private Log log;
      
          @In
          Identity    identity;
          @In
          Credentials credentials;
          @In
          UserDAO     userDAO;
      
          public boolean authenticate()
          {
              log.info("authenticating {0}", credentials.getUsername());
              log.info("authenticating {0}", credentials.getPassword());
      
              User user = userDAO.findByUsernameAndPassword(credentials.getUsername(), credentials.getPassword());
              return user != null ? true : false;
          }
      }
      



      UserDAO.java



      package ch.bemar.creditfriend.action;
      
      import javax.ejb.Local;
      
      import ch.bemar.creditfriend.action.util.GenericDAO;
      import ch.bemar.creditfriend.model.User;
      
      @Local
      public interface UserDAO extends GenericDAO<User, Long>
      {
      
          User findByUsernameAndPassword(String username, String password);
      }





      UserDAOImpl.java


      package ch.bemar.creditfriend.action;
      
      import javax.ejb.Stateless;
      import javax.persistence.Query;
      
      import org.jboss.seam.annotations.AutoCreate;
      import org.jboss.seam.annotations.Name;
      
      import ch.bemar.creditfriend.action.util.GenericDAOSeamJPAImpl;
      import ch.bemar.creditfriend.model.User;
      
      @Stateless
      @Name("userDAO")
      @AutoCreate
      public class UserDAOImpl extends GenericDAOSeamJPAImpl<User, Long> implements UserDAO
      {
      
          @Override
          public User findByUsernameAndPassword(String username, String password)
          {
              String sql = "from User user where user.namePassword = ? and user.nameUsername = ?";
              Query query = this.entityManager.createQuery(sql);
              query.setParameter(1, password);
              query.setParameter(2, username);
              User user = (User) query.getSingleResult();
              return user;
          }
      
      }






      GenericDAOSeamJPAImpl


      package ch.bemar.creditfriend.action.util;
      
      import java.io.Serializable;
      
      import javax.persistence.EntityManager;
      
      import org.jboss.seam.annotations.In;
      
      public abstract class GenericDAOSeamJPAImpl<T, ID extends Serializable> implements GenericDAO<T, ID>
      {
          private Class<T>        entityClass;
      
          @In
          protected EntityManager entityManager;
      }





      GenericDAO


      package ch.bemar.creditfriend.action.util;
      
      import java.io.Serializable;
      
      public interface GenericDAO<T,ID extends Serializable>{
          
      }



      Whole stacktrace


      org.jboss.deployers.spi.DeploymentException: Error during deploy: vfsfile:/E:/jboss-5.1.0.GA/server/default/deploy/creditfriend.ear/creditfriend.jar/
           at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49)
           at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:177)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1210)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
           at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
           at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
           at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
           at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
           at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
           at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
           at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
           at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
           at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
           at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:362)
           at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
           at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
           at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
           at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
           at java.lang.Thread.run(Unknown Source)
      Caused by: java.lang.NoClassDefFoundError: RegisterAction
           at java.lang.ClassLoader.defineClass1(Native Method)
           at java.lang.ClassLoader.defineClass(Unknown Source)
           at org.jboss.classloader.spi.base.BaseClassLoader.access$200(BaseClassLoader.java:63)
           at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:572)
           at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:532)
           at java.security.AccessController.doPrivileged(Native Method)
           at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:530)
           at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:507)
           at org.jboss.classloader.spi.base.BaseDelegateLoader.loadClass(BaseDelegateLoader.java:134)
           at org.jboss.classloader.spi.filter.FilteredDelegateLoader.loadClass(FilteredDelegateLoader.java:131)
           at org.jboss.classloader.spi.base.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:452)
           at org.jboss.classloader.spi.base.ClassLoaderManager.nextTask(ClassLoaderManager.java:251)
           at org.jboss.classloader.spi.base.ClassLoaderManager.process(ClassLoaderManager.java:150)
           at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:265)
           at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1119)
           at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:798)
           at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:441)
           at java.lang.ClassLoader.loadClass(Unknown Source)
           at java.lang.ClassLoader.loadClassInternal(Unknown Source)
           at java.lang.Class.forName0(Native Method)
           at java.lang.Class.forName(Unknown Source)
           at org.jboss.deployers.plugins.annotations.WeakClassLoaderHolder.loadClass(WeakClassLoaderHolder.java:72)
           at org.jboss.deployers.plugins.annotations.AbstractElement.getOwner(AbstractElement.java:73)
           at org.jboss.deployment.OptAnnotationMetaDataDeployer.getClasses(OptAnnotationMetaDataDeployer.java:172)
           at org.jboss.deployment.OptAnnotationMetaDataDeployer.processJBossMetaData(OptAnnotationMetaDataDeployer.java:133)
           at org.jboss.deployment.OptAnnotationMetaDataDeployer.processMetaData(OptAnnotationMetaDataDeployer.java:84)
           at org.jboss.deployment.AnnotationMetaDataDeployer.deploy(AnnotationMetaDataDeployer.java:177)
           at org.jboss.deployment.AnnotationMetaDataDeployer.deploy(AnnotationMetaDataDeployer.java:93)
           at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
           ... 25 more
      Caused by: java.lang.ClassNotFoundException: RegisterAction
           at java.net.URLClassLoader$1.run(Unknown Source)
           at java.security.AccessController.doPrivileged(Native Method)
           at java.net.URLClassLoader.findClass(Unknown Source)
           at java.lang.ClassLoader.loadClass(Unknown Source)
           at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
           at java.lang.ClassLoader.loadClass(Unknown Source)
           at java.lang.ClassLoader.loadClassInternal(Unknown Source)
           at java.lang.Class.forName0(Native Method)
           at java.lang.Class.forName(Unknown Source)
           at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:292)
           at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1119)
           at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:798)
           at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:441)
           at java.lang.ClassLoader.loadClass(Unknown Source)
           at java.lang.ClassLoader.loadClassInternal(Unknown Source)
           ... 54 more