Announcement Announcement Module
Collapse
No announcement yet.
Specification violation [EJB3 JPA 6.2.1.2] -You have not defined non-jta-data-source Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Hello friends,

    Problems seems to have with @Resource(name="toDoModel") in following code

    package org.zkforge.zktodo2;

    import static java.lang.System.out;

    import java.util.Date;
    import java.util.List;

    import javax.annotation.Resource;

    import org.zkoss.zk.ui.event.Event;
    import org.zkoss.zul.Datebox;
    import org.zkoss.zul.Intbox;
    import org.zkoss.zul.ListModel;
    import org.zkoss.zul.ListModelList;
    import org.zkoss.zul.Listbox;
    import org.zkoss.zul.Textbox;

    public class ZkToDoControllerV3 extends GenericSpringComposer {

    private static final long serialVersionUID = 2560535692993939331L;
    protected transient Textbox name;
    protected transient Intbox priority;
    protected transient Datebox date;
    protected transient Listbox list;

    public ZkToDoControllerV3(){
    return;
    }

    @Resource(name="toDoModel")
    protected transient ZkToDoModel toDoModel = null;

    public ZkToDoModel getToDoModel() {
    return toDoModel;
    }

    public void onClick$add(Event e) {
    Date dateValue = date.getValue();
    Integer priorityValue = priority.getValue();
    String nameValue = name.getValue();
    if( dateValue != null && priorityValue != null && nameValue != null ){
    Reminder reminder = new Reminder();
    reminder.setDate(date.getValue());
    reminder.setName(name.getValue());
    reminder.setPriority(priority.getValue());
    this.toDoModel.persistEvent(reminder);
    List<Reminder> reminders = this.toDoModel.findAll();
    ListModel listModel = this.list.getModel();
    ListModelList listModelList = (ListModelList)listModel;
    listModelList.clear();
    listModelList.addAll(reminders);
    }
    return;
    }

    public void onClick$update(Event e) {
    Reminder selectedReminder = this.toDoModel.getSelectedReminder();
    if( selectedReminder != null ){
    ListModelList listModelList = (ListModelList)this.list.getModel();
    try {
    this.toDoModel.mergeEvent(selectedReminder);
    } catch (EntityNotFoundException exception){
    int index = list.getSelectedIndex();
    listModelList.remove(index);
    alert("Reminder "+selectedReminder.getName()+" has been deleted by another user.");
    if( listModelList.size() > 0 ){
    selectedReminder = (Reminder)listModelList.get(0);
    list.setSelectedIndex(0);
    name.setValue(selectedReminder.getName());
    date.setValue(selectedReminder.getDate());
    priority.setValue(selectedReminder.getPriority());
    } else {
    selectedReminder = null;
    }
    }
    List<Reminder> reminders = toDoModel.findAll();
    listModelList.clear();
    listModelList.addAll(reminders);
    }
    }

    public void onClick$delete(Event e) {
    Reminder selectedReminder = this.toDoModel.getSelectedReminder();
    if( null != selectedReminder ){
    ListModel listModel = this.list.getModel();
    ListModelList listModelList = (ListModelList)listModel;
    int index = listModelList.indexOf(selectedReminder);
    try {
    this.toDoModel.deleteEvent(selectedReminder);
    } catch (EntityNotFoundException exception ){
    out.println("This is harmless as someone else has already deleted this item.");
    }
    listModelList.remove(selectedReminder);
    if( index >= listModelList.size() ){
    index = listModelList.size() - 1;
    }
    if( listModelList.size() > 0 ){
    selectedReminder = (Reminder)listModelList.get(index);
    list.setSelectedIndex(index);
    name.setValue(selectedReminder.getName());
    date.setValue(selectedReminder.getDate());
    priority.setValue(selectedReminder.getPriority());
    } else {
    selectedReminder = null;
    }
    }
    }
    }

    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   
        -->	
    
    	<tx:annotation-driven />
    
    	<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 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>

    Can anyone help?

    Thanks.

    Comment


    • #17
      try mappedName instead

      try @Resource(mappedName="toDoModel") instead.
      Check this thread

      Comment


      • #18
        Hello ashishlin,

        Thanks for reply.

        I tried it and now it gives following error.

        Caused by: java.lang.ClassNotFoundException: org.aopalliance.intercept.MethodInterceptor

        Thanks.

        Comment


        • #19
          missing jar?

          generally it means you are missing some jar file. google about it.

          Comment


          • #20
            Hello ashishlin,

            After adding all missing jar files now it gives following error..

            14:37:55,265 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceCon nectionProvider
            14:37:55,265 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
            14:37:55,390 WARN [SettingsFactory] Could not obtain connection metadata
            org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (error in script file line: 1 Unexpected token UNIQUE, requires COLLATION in statement [SET DATABASE UNIQUE])
            at org.apache.commons.dbcp.BasicDataSource.createData Source(BasicDataSource.java:1225)
            at org.apache.commons.dbcp.BasicDataSource.getConnect ion(BasicDataSource.java:880)

            Caused by: java.sql.SQLException: error in script file line: 1 Unexpected token UNIQUE, requires COLLATION in statement [SET DATABASE UNIQUE]
            at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
            at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)

            Thanks.

            Comment


            • #21
              Hello friends,

              at last I was able to compile application succesfully.

              Previous error was due to wrong values in .properties file for database url.

              Thanks.

              Comment

              Working...
              X