1 2 Previous Next 20 Replies Latest reply on May 7, 2009 1:12 PM by peterj Go to original post
      • 15. Re: no persistent classes found for query class

         

        <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%><%@taglib
         uri="http://java.sun.com/jsf/html" prefix="h"%><%@ page language="java" contentType="text/html; charset=ISO-8859-1"
         pageEncoding="ISO-8859-1"%>
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Login</title>
        </head>
        <body>
        
        <f:view><br><br><br>
             <h:outputLabel value="Login name"></h:outputLabel>        <h:inputText value="#{loginBean.loginName}"></h:inputText>
            <br>
              <h:outputText value="Password"></h:outputText>          <h:inputText value="#{loginBean.password}"></h:inputText>   
        
         <br><br><br><h:form>
         <h:commandButton value="Submit" action="#{loginBean.login}"></h:commandButton>
         </h:form><br><br><br><br></f:view>
        </body>
        </html>


        this is the jsf where i call the LoginBean from

        • 16. Re: no persistent classes found for query class
          peterj

          Based on what you are showing I am not sure if you are using straight Hibernate, or is you are using JPA (the amount of commented-out code makes it difficult to follow). My guess is that you are using JPA. In which case you have not declared the entity class. Add an @Entity annotation to the User class and see if that fixes it.

          • 17. Re: no persistent classes found for query class

            i did it as you said but nothing hasd been changed.Could you please tell me how to use jpa in jboss.some excamples.as you said i am using jpa.


            import javax.naming.InitialContext;
            import javax.persistence.EntityManager;
            import javax.persistence.EntityManagerFactory;
            import javax.persistence.NoResultException;
            import javax.persistence.Persistence;
            import javax.persistence.Query;
            
            import org.hibernate.Session;
            import org.hibernate.SessionFactory;
            
            
            public class LoginBean {
            private String LoginName;
            private String password;
            
            public String getLoginName() {
             return LoginName;
            }
            public void setLoginName(String loginName) {
             LoginName = loginName;
            }
            public String getPassword() {
             return password;
            }
            public void setPassword(String password) {
             this.password = password;
            }
            public String login() throws Exception{
            
            
             EntityManager em = Contexts.getEntityManager();
            
             Query query = em.createQuery(
             "from User user");
            
            
            
            
            
             // execute query
             try {
             User user = (User)query.getSingleResult();
             // store found user to session
             Contexts.getSession().setAttribute("user", user);
             } catch (NoResultException e) {
             // no user found - return failure
             e.printStackTrace();
             return "failure";
             }
            
             //return success
             return "success";
            }
            }
            


            • 18. Re: no persistent classes found for query class
              dgeraskov

              I created the simplest jpa project. With only 1 entity.
              package model;

              import javax.persistence.*;
              
              @Entity
              public class Article implements java.io.Serializable {
              
               @Id
               @GeneratedValue(strategy = GenerationType.AUTO)
               private Short id_Article;
              
               @Column(name="ar_name")
               private String arName;
              
               public Article() {}
              
               public Article(short idArticle, String arName) {
               this.id_Article = idArticle;
               this.arName = arName;
               }
               ...get/set
              }



              package model;
              
              import java.util.List;
              import javax.persistence.*;
              
              public class R {
              
               /**
               * @param args
               */
               public static void main(String[] args) {
               EntityManagerFactory emf =
               Persistence.createEntityManagerFactory("article_jpa");
              
               // First unit of work
               EntityManager em = emf.createEntityManager();
               EntityTransaction tx = em.getTransaction();
               tx.begin();
               Query max = em.createQuery("from Article a");
               //max.setMaxResults(1);
               List l = max.getResultList();
               for (int i = 0; i < l.size(); i++) {
               Article ar = (Article) l.get(i);
               System.out.println(ar.getIdArticle() + "\t" + ar.getArName());
               }
               if (l.size() == 0){
               for (short i = 1; i < 10; i++){
               Article article = new Article(i, "Article №" + i);
               em.persist(article);
               }
               }
               tx.commit();
               em.close();
              
               emf.close();
               System.out.println("finish");
               }
              }


              and persistence.xml
              <?xml version="1.0" encoding="UTF-8"?>
              <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
               <persistence-unit name="article_jpa">
               <class>model.Article</class>
               <exclude-unlisted-classes>true</exclude-unlisted-classes>
               <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
               <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
               <property name="hibernate.connection.url" value="jdbc:postgresql:test"/>
               <property name="hibernate.connection.username" value="postgres"/>
               <property name="hibernate.connection.password" value="postgres"/>
              
               <property name="hibernate.current_session_context_class"
               value="org.hibernate.context.JTASessionContext"/>
               </properties>
               </persistence-unit>
              </persistence>


              Database table has only 2 columns: id_article and ar_name.
              You can use this example as starting point. Change connection settings to your database, create table Article and see how it works.

              • 19. Re: no persistent classes found for query class

                thanks for your answer,
                i gave up and started to do it through native hibernate.

                but your answer turned me again to annotations :)

                is there any source about this subject ?

                and what about jndi bindings?

                thanks

                • 20. Re: no persistent classes found for query class
                  peterj

                  How have you packaged your application? EAR or WAR? Could you list the full contents of the package (use jar-tf). I suspect that files are not in the proper place.

                  There are many EJB3 books on the market. If you don't have one, I suggest that you get one. Any of those books should be able to tell you everything you need.

                  1 2 Previous Next