Announcement Announcement Module
Collapse
No announcement yet.
no persistent classes found for query class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • no persistent classes found for query class

    Hello friends,

    I have created example project with Spring 3.0.3 + JPA + Hibernate + ZKOSS
    with JBOSS 5.1 GA server

    Application compiles fine without any error .

    But when I am executing page. it gives following error.

    17:15:03,703 WARN [QuerySplitter] no persistent classes found for query class: from org.zkforge.zktodo2.Reminder


    Following is my web.xml file

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>zk5</display-name>
      
      <!-- Spring -->
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>classpath:dataSourceContext.xml,classpath:spring-context.xml</param-value>
    	</context-param>
    	
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	
    	<listener>
    		<!-- The Spring RequestContextLister uses thread bound variables so to 
    		use this Spring freatures requires that we apply <disable-event-thread /> 
    		within zk.xml -->
    		<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    	</listener>
    	
    	
    	
    	<!-- Spring -->
    	
      <listener>
      	<description>
      	Used to cleanup when a session is destroyed</description>
      	<display-name>
      	
      	ZK Session cleaner</display-name>
      	
      	<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
      </listener>
      <servlet>
      	<description>
      	The ZK loader for ZUML pages</description>
      	<servlet-name>zkLoader</servlet-name>
      	<servlet-class>
      	org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
      	<init-param>
      		<param-name>update-uri</param-name>
      		<param-value>/zkau</param-value>
      	</init-param>
      	<load-on-startup>1</load-on-startup>
      </servlet>
      <servlet>
      	<description>
      	The asynchronous update engine for ZK</description>
      	<servlet-name>auEngine</servlet-name>
      	<servlet-class>
      	org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
      </servlet>
      <servlet-mapping>
      	<servlet-name>zkLoader</servlet-name>
      	<url-pattern>*.zul</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
      	<servlet-name>zkLoader</servlet-name>
      	<url-pattern>*.zhtml</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
      	<servlet-name>auEngine</servlet-name>
      	<url-pattern>/zkau/*</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
        <welcome-file>index.zul</welcome-file>
      </welcome-file-list>
    </web-app>

    Following is my spring-context.xml file

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xsi:schemaLocation="
    	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    	">
        
    	<!-- 
        JPA config   
        -->	
    
    	
    
    	<bean id="entityManagerFactory"
    		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    		p:persistence-xml-location="classpath:META-INF/persistence.xml"
    		p:data-source-ref="dataSource"
    		>
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
    				p:showSql="true"
    				p:generateDdl="true">
    			</bean>
    		</property>
    		<property name="jpaProperties">
    			<value>
    			hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
    			hibernate.dialect=${hibernate.dialect}
    			hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
    			</value>
    		</property>
    	</bean>
    	
    	<bean id="transactionManager"
    		class="org.springframework.orm.jpa.JpaTransactionManager" 
    		p:entity-manager-factory-ref="entityManagerFactory"
    	/>
    	
    	<tx:annotation-driven />
    	
    	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    
        <!-- 
        JPA helpers
        --> 
        
        <bean id="basicDao" class="org.zkforge.zktodo2.BasicDao" />
    
        <!-- 
        First article classes
        --> 
    
    	<bean id="reminderService" class="org.zkforge.zktodo2.ReminderService" 
    		p:basicDao-ref="basicDao"
    	/>
    
    	<bean id="toDoControllerV1" class="org.zkforge.zktodo2.ZkToDoControllerV1" 
    		p:reminderService-ref="reminderService" scope="prototype"
    	/>
    
        <!-- 
        Data binding enhancement classes
        --> 
    
    	<!-- 
    	Note that the following bean is session scoped. 
    	--> 
    	<bean id="toDoModel" class="org.zkforge.zktodo2.ZkToDoModelImpl" 
    			p:reminderService-ref="reminderService" scope="session">
    		<!-- 
    		// scoped proxy is commented out as only referenced by a prototype bean
    		// if you wanted to pass this bean to a singleton you need to include
    		// the following configurration.   
    		<aop:scoped-proxy proxy-target-class="false"/>
    		-->	
    	</bean>
    
    	<bean id="toDoControllerV2" class="org.zkforge.zktodo2.ZkToDoControllerV2" 
    		p:toDoModel-ref="toDoModel" scope="prototype"
    	/>
        
    </beans>

    Following is my dataSourceContext.xml file

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="
    	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
    	">
    
    	<bean id="dataSource"
    		class="org.apache.commons.dbcp.BasicDataSource"
    		destroy-method="close"
    		p:driverClassName="${jdbc.driver}"
    		p:url="${jdbc.url}"
    		p:username="${jdbc.username}"
    		p:password="${jdbc.password}" />
    
    	
    	
    	<!-- 
        Injected properties
        --> 
        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    	    <property name="locations">
    	    <list>
                <value>classpath:zktodo2.properties</value>
    	    </list>
    	    </property>
            
        </bean>
        
    
    </beans>

    Following is my /META-INF/persistence.xml file

    Code:
    <?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="ExamplePU" transaction-type="RESOURCE_LOCAL">
      <non-jta-data-source>java:/gwtDS</non-jta-data-source>
      </persistence-unit>
    </persistence>

    Following is my zktodo2.properties file

    Code:
    jdbc.url=jdbc:hsqldb:mem:salvation
    jdbc.username=sa
    jdbc.password=
    jdbc.driver=org.hsqldb.jdbcDriver
    hibernate.dialect=org.hibernate.dialect.HSQLDialect
    hibernate.hbm2ddl.auto=update


    Following is my Reminder.java file

    Code:
    package org.zkforge.zktodo2;
    
    import java.util.Date;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Table;
    
    @Entity
    @Table(name = "REMINDER")
    public class Reminder {
    	@Override
    	public boolean equals(Object obj) {
    		if( obj instanceof Reminder ){
    			Reminder other = (Reminder) obj;
    			if( this.getId() != null && other.getId() != null && this.getId().equals(other.getId())){
    				return true;
    			}
    		}
    		return false;
    	}
    	@Override
    	public int hashCode() {
    		return Long.valueOf(this.getId()).hashCode();
    	}
    	@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    	@Column(name = "REMINDER_ID")
    	private Long id;
    	
    	@Column(name = "NAME")
    	private String name;
    	
    	@Column(name = "PRIORITY")
    	private int priority;
    	
    	@Column(name = "DATE")
    	private Date date;
    	
    	public Reminder(){}
    	public Reminder(String name,int priority,Date date){
    		this.name = name;
    		this.priority = priority;
    		this.date = date;
    	}
    	public Date getDate() {
    		return date;
    	}
    	public void setDate(Date date) {
    		this.date = date;
    	}
    	public int getPriority() {
    		return priority;
    	}
    	public void setPriority(int priority) {
    		this.priority = priority;
    	}
    	public Long getId() {
    		return id;
    	}
    	public void setId(Long id) {
    		this.id = id;
    	}
    	public String getName() {
    		return name;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
    }

    Can any one help me regarding the matter.

    Please let me know if you need anything else from my side.

    Thanks.

  • #2
    @amar4kintu,

    Originally posted by amar4kintu View Post

    17:15:03,703 WARN [QuerySplitter] no persistent classes found for query class: from org.zkforge.zktodo2.Reminder

    ... ... ...

    Following is my /META-INF/persistence.xml file

    Code:
    <?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="ExamplePU" transaction-type="RESOURCE_LOCAL">
      <non-jta-data-source>java:/gwtDS</non-jta-data-source>
      </persistence-unit>
    </persistence>
    The reason it does not see "org.zkforge.zktodo2.Reminder" is because you did not specify where "persistence-unit" should look for it.

    Not to rely on JPA's own auto quite limited "entity scan", you have several options:

    1. Specify which class(es) you want to map explicitly:

    Code:
    <?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="ExamplePU" transaction-type="RESOURCE_LOCAL">
      <non-jta-data-source>java:/gwtDS</non-jta-data-source>
    
      <class>org.zkforge.zktodo2.Reminder</class>
    
      </persistence-unit>
    </persistence>
    2. Specify JAR(s) that contains entities you'd like to map:

    Code:
    <?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="ExamplePU" transaction-type="RESOURCE_LOCAL">
      <non-jta-data-source>java:/gwtDS</non-jta-data-source>
    
      <jar-file>reminder.jar</jar-file>
    
      </persistence-unit>
    </persistence>

    3. Enable Hibernate entity autodetection:
    (... is not JPA compliant, but would work with Hibernate )

    Code:
    <?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="ExamplePU" transaction-type="RESOURCE_LOCAL">
      <non-jta-data-source>java:/gwtDS</non-jta-data-source>
    
      <properties>
        <property name="hibernate.archive.autodetection" value="class, hbm"/>
      </properties>
    
      </persistence-unit>
    </persistence>
    /Anatoly

    Comment


    • #3
      Hello litius,

      Thanks for the answer.

      It is a perfect answer !!!

      Thanks.

      Comment

      Working...
      X