Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Specification violation [EJB3 JPA 6.2.1.2] -You have not defined non-jta-data-source

  1. #1
    Join Date
    Sep 2010
    Posts
    19

    Default Specification violation [EJB3 JPA 6.2.1.2] -You have not defined non-jta-data-source

    Hello friends,

    I am trying to create a web application using Spring 3.0.3, JPA 1.0, Hibernate 3, zkoss 5 and JBOSS 5.1 server with jdk support.

    Following is list of jar files in my /WEB-INF/lib directory
    Code:
    commons-dbcp-all-1.3.jar
    commons-io.jar
    org.springframework.*-3.0.3.RELEASE.jar
    zcommon.jar
    zcommons-el.jar
    zhtml.jar
    zk.jar
    zkplus.jar
    zul.jar
    zweb.jar

    Following is my /WEB-INF/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 -->
        
        <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>
        
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:dataSourceContext.xml,classpath:spring-context.xml</param-value>
        </context-param>
        
        <!-- 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 /src/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:context="http://www.springframework.org/schema/context"
        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/context http://www.springframework.org/schema/context/spring-context.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
        ">
        
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
        
        <!-- import the dataSource definition -->
        <import resource="dataSourceContex.xml"/>
        
        <!--
            Activates a load-time weaver for the context. Any bean within the context that
            implements LoadTimeWeaverAware (such as LocalContainerEntityManagerFactoryBean)
            will receive a reference to the autodetected load-time weaver.
        -->
        <context:load-time-weaver/>
        
        <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
        
        <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
        
        
        <!-- JPA primary EntityManagerFactory -->
          <bean id="entityManagerFactory" lazy-init="true"
              class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
              p:persistenceUnitName="ExamplePU"
              p:jpaVendorAdapter-ref="jpaVendorAdapter"
              p:jpaDialect-ref="jpaDialect"
              p:dataSource-ref="dataSource"/>
    
    
        
        
        <bean id="transactionManager"
            class="org.springframework.orm.jpa.JpaTransactionManager" 
            p:entity-manager-factory-ref="entityManagerFactory"
        />
        
        <!-- 
        JPA config   
        -->    
        
        <tx:annotation-driven />
        
        <!-- 
        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 /src/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="org.hsqldb.jdbcDriver" p:url="jdbc:hsqldb:mem:zktodo"
                p:username="sa" p:password=""/>
        
     
    
    </beans>

    Following is my /src/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">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
          <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
          <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
          <property name="hibernate.showsql" value="true"/>
          <property name="hibernate.cache.use_second_level_cache" value="false"/>
        </properties>
      </persistence-unit>
    </persistence>

    JOBSS server gives me following error

    Code:
    13:27:02,250 INFO  [PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitName=#ExamplePU
    13:27:02,265 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=#ExamplePU state=Create
    java.lang.RuntimeException: Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: ExamplePU
    	at org.jboss.jpa.deployment.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:124)
    	at org.jboss.jpa.deployment.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:275)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    Can any one help me in solving the problem.
    Thanks.

  2. #2
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Add following line to persistence.xml:

    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">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
          <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
          <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
          <property name="hibernate.showsql" value="true"/>
          <property name="hibernate.cache.use_second_level_cache" value="false"/>
        </properties>
      </persistence-unit>
      <non-jta-data-source>jndi_name_of_jboss_datasource</non-jta-data-source>
    </persistence>
    You need to define a data source in your container (JBoss) and give it a jndi name and access it through org.springframework.jndi.JndiObjectFactoryBean.
    Use BasicDataSource only for test purposes, it is not meant for production environment.

  3. #3
    Join Date
    Sep 2010
    Posts
    19

    Default

    Hello Enrico Pizzi,

    Thanks for the reply.

    I will try creating jndi in my JBOSS and give it try too.

    But can you please tell me what is wrong with current code using Basic data source? I am just making a test application currently to learn things in spring.

    Thanks.

  4. #4
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Your current persistence configuration requires a non-jta data source declared in your persistence.xml. The declaration involves giving the jndi name of the resource. Your jndi host is your container, so you must either register your SimpleDataSource as a jndi resource on JBoss, OR use a Datasource defined directly in JBoss.

    The second option is the way to go, because it's simpler and more correct. Why more correct? Because in a j2ee application access to database should always be container-driven. This is because your application server gives you a more secure, monitorable, testable, and enhanced environment: think, for example, of the transactional services (jta transaction managers) that are tied to the datasource defined in the container, or the multi-datasource and datasource factory patterns.

    Thus, always use container-driven datasources for your j2ee applications. Spring's own defined datasources like SimpleDataSource are only there for:
    - non-web applications that still need database access;
    - unit testing (with junit etc.).

  5. #5
    Join Date
    Sep 2010
    Posts
    19

    Default

    Hello Enrico Pizzi,

    Thanks for the answer.

    Can you tell me how to make a configuration of Hibernate so that it does not require <non-jta-data-source>

    Is there any settings for that.

    I tried https://src.springframework.org/svn/...les/petclinic/ from my pc and it configured and run fine without any problem.

    Now I am trying same things with some changes and it asks for <non-jta-data-source>

    In that application they have used hsql in memory database and in my application also I am using hsql in memory database. I am using same Spring 3.0.3 jar files that I used with that application.

    Only difference is that they used toplink classes and I am using hibernate classes instead.


    Thanks.

  6. #6
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    TopLink and Hibernate are two very different ORM frameworks, and so their Spring integration also differs, but you shouldn't have any problem with Hibernate since it's maybe the most Spring supported ORM. I suggest you read chapter 13.3 of the Spring 3 reference guide.

  7. #7
    Join Date
    Sep 2010
    Posts
    19

    Default

    Hello Enrico Pizzi,

    Thanks for the reply.

    I created no tx datasource in JBOSS and assigned it to <non-jta-data-source> tag in persistence.xml file and it seems to work.. But now I am getting following problem... in JBOSS. it says "mapped-name is required"


    [CODE]
    14:31:39,171 INFO [PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitName=#ExamplePU
    14:31:39,203 INFO [Version] Hibernate Annotations 3.4.0.GA
    14:31:39,218 INFO [Environment] Hibernate 3.3.1.GA
    14:31:39,218 INFO [Environment] hibernate.properties not found
    14:31:39,218 INFO [Environment] Bytecode provider name : javassist
    14:31:39,218 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
    14:31:39,281 INFO [Version] Hibernate Commons Annotations 3.1.0.GA
    14:31:39,281 INFO [Version] Hibernate EntityManager 3.4.0.GA
    14:31:39,296 INFO [Ejb3Configuration] Processing PersistenceUnitInfo [
    name: ExamplePU
    ...]
    14:31:39,312 WARN [Ejb3Configuration] Persistence provider caller does not implement the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null.
    14:31:39,359 INFO [AnnotationBinder] Binding entity from annotated class: org.zkforge.zktodo2.Reminder
    14:31:39,390 INFO [EntityBinder] Bind entity org.zkforge.zktodo2.Reminder on table REMINDER
    14:31:39,421 INFO [Version] Hibernate Validator 3.1.0.GA
    14:31:39,453 INFO [HibernateSearchEventListenerRegister] Unable to find org.hibernate.search.event.FullTextIndexEventListe ner on the classpath. Hibernate Search is not enabled.
    14:31:39,500 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceCon nectionProvider
    14:31:39,531 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
    14:31:39,578 INFO [SettingsFactory] RDBMS: HSQL Database Engine, version: 1.8.0
    14:31:39,578 INFO [SettingsFactory] JDBC driver: HSQL Database Engine Driver, version: 1.8.0
    14:31:39,593 INFO [Dialect] Using dialect: org.hibernate.dialect.HSQLDialect
    14:31:39,593 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
    14:31:39,593 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerL ookup
    14:31:39,609 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
    14:31:39,609 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
    14:31:39,609 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
    14:31:39,609 INFO [SettingsFactory] JDBC batch size: 15
    14:31:39,609 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
    14:31:39,609 INFO [SettingsFactory] Scrollable result sets: enabled
    14:31:39,609 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
    14:31:39,609 INFO [SettingsFactory] Connection release mode: auto
    14:31:39,609 INFO [SettingsFactory] Default batch fetch size: 1
    14:31:39,609 INFO [SettingsFactory] Generate SQL with comments: disabled
    14:31:39,609 INFO [SettingsFactory] Order SQL updates by primary key: disabled
    14:31:39,609 INFO [SettingsFactory] Order SQL inserts for batching: disabled
    14:31:39,609 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    14:31:39,609 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
    14:31:39,609 INFO [SettingsFactory] Query language substitutions: {}
    14:31:39,609 INFO [SettingsFactory] JPA-QL strict compliance: enabled
    14:31:39,609 INFO [SettingsFactory] Second-level cache: enabled
    14:31:39,609 INFO [SettingsFactory] Query cache: disabled
    14:31:39,609 INFO [SettingsFactory] Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCache ProviderBridge
    14:31:39,609 INFO [RegionFactoryCacheProviderBridge] Cache provider: org.hibernate.cache.HashtableCacheProvider
    14:31:39,609 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
    14:31:39,609 INFO [SettingsFactory] Cache region prefix: persistence.unit:unitName=#ExamplePU
    14:31:39,609 INFO [SettingsFactory] Structured second-level cache entries: disabled
    14:31:39,609 INFO [SettingsFactory] Statistics: disabled
    14:31:39,609 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
    14:31:39,625 INFO [SettingsFactory] Default entity-mode: pojo
    14:31:39,625 INFO [SettingsFactory] Named query checking : enabled
    14:31:39,656 INFO [SessionFactoryImpl] building session factory
    14:31:39,781 INFO [SessionFactoryObjectFactory] Factory name: persistence.unit:unitName=#ExamplePU
    14:31:39,781 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.in terfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org. jnp.interfaces}
    14:31:39,796 INFO [SessionFactoryObjectFactory] Bound factory to JNDI name: persistence.unit:unitName=#ExamplePU
    14:31:39,796 WARN [SessionFactoryObjectFactory] InitialContext did not implement EventContext
    14:31:39,796 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.in terfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org. jnp.interfaces}
    14:31:39,796 WARN [SessionFactoryImpl] JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
    14:31:39,812 INFO [TomcatDeployment] deploy, ctxPath=/zk5
    14:31:39,859 ERROR [StandardContext] Context [/zk5] startup failed due to previous errors
    java.lang.RuntimeException: mapped-name is required for toDoModel of deployment zk5.war
    at org.jboss.web.tomcat.service.injection.WebResource Handler.loadXmlResourceEnvRefs(WebResourceHandler. java:287)
    [QUOTE]

  8. #8
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Do you have a WebServiceContext object mapped with @Resource? If so, please note that WebServiceContext resources need to be treated specially...remove the @Resource and the error should go away.

  9. #9
    Join Date
    Sep 2010
    Posts
    19

    Default

    Hello Enrico Pizzi,

    Thanks for the answer.

    I think now problem is with zkoss implementation.

    following is class that is creating resource annotation.
    Look at function wireBeans()

    Code:
    package org.zkforge.zktodo2;
    
    import java.lang.reflect.Field;
    
    import javax.annotation.Resource;
    import javax.servlet.ServletContext;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.web.context.support.WebApplicationContextUtils;
    import org.zkoss.zk.ui.Component;
    import org.zkoss.zk.ui.util.GenericForwardComposer;
    
    public class GenericSpringComposer extends GenericForwardComposer {
    
    	private static final long serialVersionUID = -8554216461300908912L;
    
    	private ServletContext servletContext = null;
    
    	@Override
    	public void doAfterCompose(Component comp) throws Exception {
    		super.doAfterCompose(comp);
    		this.servletContext = (ServletContext) comp.getDesktop().getWebApp()
    				.getNativeContext();
    		this.wireBeans();
    	}
    
    	@Override
    	public void didActivate(Component namespace) {
    		super.didActivate(namespace);
    		try {
    			this.wireBeans();
    		} catch (IllegalArgumentException e) {
    			e.printStackTrace();
    		} catch (IllegalAccessException e) {
    			e.printStackTrace();
    		}
    	}
    
    	private void wireBeans() throws IllegalArgumentException,
    			IllegalAccessException {
    		ApplicationContext ctx = WebApplicationContextUtils
    				.getWebApplicationContext(this.servletContext);
    		
    		Field[] fields = this.getClass().getDeclaredFields();
    		for (Field f : fields) {
    			Resource annotation = f.getAnnotation(Resource.class);
    			if (annotation != null) {
    				f.setAccessible(true); // Make private fields accessible.
    				Object bean = ctx.getBean(annotation.name());
    				f.set(this, bean);
    			}
    
    		}
    		
    	}
    
    }
    I am using code which is given on zkoss site.
    I don't know if you are aware of zkoss but can you please tell me how to treat WebServiceContext resources specially

    Thanks.
    Thanks.

  10. #10
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    No, I didn't know of ZK till now. To make it work with Spring, I think you should use ZK Spring 1.1.0 Release, which is an integration framework between ZK and Spring, and follow this guide to set it up: http://docs.zkoss.org/wiki/Spring#ZK_.2B_Spring

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •