3 Replies Latest reply on Apr 24, 2009 1:18 PM by ioannis ntantis

    Use criteria in a seam action class ?

    ioannis ntantis Newbie

      Hi all,

      I have made an application using seam-gen . What i  want to do is use hibernate criteria instead of a query. I find it difficult because no matter when I try i cant get it to work.

      Below is the method that i want to use criteria in:

       public void queryCars() {
                carsList = new ArrayList<Car>();
                 EntityManagerImpl entityManagerImpl = (EntityManagerImpl)  entityManager.getDelegate();
                   session = entityManagerImpl.getSession();
                   Criteria criteria = session.createCriteria(Car.class);
                if (make != null) {
                     System.out.println("query: " + query);
                     criteria.add(Restrictions.eq("brandFK", make));
               List<Car> cars= new ArrayList<Car>();;
               for (Car car : carsList) {
               carsList = new ArrayList<Car>();
               System.out.println("motorcyclesList size is1 : " + carsList.size());

      I found this in a tutorial but it does not even compile.

      If you could somehow assist me. I know i dont give many infos here(because am lost) but if u can, please help.

      Thanks in advance.


      Click HELP for text formatting instructions. Then edit this text and check the preview.

        • 1. Re: Use criteria in a seam action class ?
          Ralf H. Newbie


          i faced the problem too and after some tryouts i found a solution.

          Try that:

          HibernateSessionProxy proxy = (HibernateSessionProxy) this.entityManager.getDelegate();
          Criteria criteria = proxy.createCriteria( MyClass.class );

          Does it work??


          • 2. Re: Use criteria in a seam action class ?
            Arbi Sookazian Master

            Seam in Action:

            When you’re using JPA, you can always get down to the provider interface by calling
            the getDelegate() method on the EntityManager instance. But you have to perform
            a cast that makes an assumption about the underlying JPA provider:
            Session session = (Session) entityManager.getDelegate();
            You can define a factory in Seam to hide the cast:
            <factory name="hibernateSession" value="#{entityManager.delegate}"
            You then use the @In annotation to inject the value of this factory into your component:
            @In private Session hibernateSession;

            • 3. Re: Use criteria in a seam action class ?
              ioannis ntantis Newbie

              Hi all,

              First of all thanks for the replies.

              Sorry for the late post but my pc motherboard burnt out so i had to replace it...

              The proxy thing seems to be working for me. But this:

              '<facory name="hibernateSession" value="#{entityManager.delegate}"

              I dont really understand it . So i will have to use sessionproxy.

              just one more question. Performance wise, which of the two sollutions iis better?