Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to implement CRUD operations in an RCP application
How to implement CRUD operations in an RCP application [message #534660] Wed, 19 May 2010 18:43 Go to next message
No real name is currently offline No real name
Messages: 1
Registered: May 2010
Junior Member
i'm working on a RCP project with spring and hibernate, i'm a beginner in a plugin developpemnt, i create an action to inserts some fiels in my database using mysql. And i keep getting this exception:

org.springframework.beans.factory.CannotLoadBeanClassExcepti on: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource ] for bean with name 'dataSource'

ApplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource"
		>
		<property name="driverClassName"><!-- <value>org.hsqldb.jdbcDriver</value> -->
			<value>com.mysql.jdbc.Driver</value>
		</property>
		<property name="url">
			<value>jdbc:mysql://localhost:3306/i-way</value>
		</property>
		<property name="username">
			<value>root</value>
		</property>
		<property name="password">
			<value>berrom</value>
		</property>
	</bean>

	<bean id="myHibernateProperties"
		class="org.springframework.beans.factory.config.PropertiesFactoryBean">
		<property name="properties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQLDialect
			</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
	</bean>

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="annotatedClasses">
			<list>
				<value>model.User</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<ref bean="myHibernateProperties" />
		</property>
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
	</bean>

	<bean id="jdbcExceptionTranslator"
		class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
	</bean>
	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
		<property name="jdbcExceptionTranslator">
			<ref bean="jdbcExceptionTranslator" />
		</property>
	</bean>

	<bean id="UserDAO" class="model.UserDAO">
		<property name="hibernateTemplate">
			<ref bean="hibernateTemplate" />
		</property>
	</bean>
</beans>



AddUserAction.java

package identification;

public class AddUserAction extends Action implements
ISelectionListener, IWorkbenchAction {
	
	private final IWorkbenchWindow window;
	  public final static String ID = "org.eclipsercp.identification.addUser";
	  private IStructuredSelection selection;

	  public AddUserAction(IWorkbenchWindow window) {
	    this.window = window;
	    setId(ID);
	    setText("&Add User...");
	    setToolTipText("Add a user to your users.");
	    window.getSelectionService().addSelectionListener(this);
	  }

	public void run() {
		
	ApplicationContext ctx =(ApplicationContext) new FileSystemXmlApplicationContext("/SpringConfig/applicationContext.xml");
		//ApplicationContext ctx=MonContext.getCtx();
		UserService us = (UserService) ctx.getBean("UserService");
		us.ajoutUser("aaaaaaa", "bbbbbb");
		
	}


}


and here is the error

Start RCP Application
May 19, 2010 6:23:47 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@140243b: startup date [Wed May 19 18:23:47 BST 2010]; root of context hierarchy
May 19, 2010 6:23:47 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [D:\stage fin d'etudes\eclipse-rcp-galileo-win32\eclipse\SpringConfig\applicationContext.xml]
May 19, 2010 6:23:49 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@fd981a: defining beans [dataSource,myHibernateProperties,sessionFactory,jdbcExceptionTranslator,hibernateTemplate,UserDAO,UserBO,transactionManager,UserService]; root of factory hierarchy
May 19, 2010 6:23:49 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@fd981a: defining beans [dataSource,myHibernateProperties,sessionFactory,jdbcExceptionTranslator,hibernateTemplate,UserDAO,UserBO,transactionManager,UserService]; root of factory hierarchy
!SESSION 2010-05-19 18:23:38.232 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_18
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Framework arguments:  -application Identification.application
Command-line arguments:  -application Identification.application -data C:\Users\H\Desktop\workspaces\workspace\Identification -dev file:C:/Users/H/Desktop/workspaces/workspace/.metadata/.plugins/org.eclipse.pde.core/Identification.application/dev.properties -os win32 -ws win32 -arch x86 -consolelog

!ENTRY org.eclipse.ui 4 0 2010-05-19 18:23:49.597
!MESSAGE Unhandled event loop exception
!STACK 0
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] for bean with name 'dataSource' defined in file [D:\stage fin d'etudes\eclipse-rcp-galileo-win32\eclipse\SpringConfig\applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1223)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
	at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1292)
	at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:858)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:545)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
	at identification.AddUserAction.run(AddUserAction.java:53)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
	at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:452)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3910)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3503)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at identification.Application.start(Application.java:31)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at org.eclipse.core.runtime.internal.adaptor.ContextFinder.loadClass(ContextFinder.java:129)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at org.springframework.util.ClassUtils.forName(ClassUtils.java:258)
	at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1244)
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1215)
	... 38 more



i use the springframework 3.0.2 release librairies
I really need your help guys, or if someone has a simple example for crud operations with eclipse RCP using Spring and hibernate!! i will appreciate it
Re: How to implement CRUD operations in an RCP application [message #537504 is a reply to message #534660] Wed, 02 June 2010 16:34 Go to previous messageGo to next message
alan kemp is currently offline alan kemp
Messages: 17
Registered: October 2009
Junior Member
i feel your pain. i tried to implement JPA using eclipselink in a RCP plugin and was not successful. i would still like to be able to do this. good luck Cool

Re: How to implement CRUD operations in an RCP application [message #537675 is a reply to message #534660] Thu, 03 June 2010 10:37 Go to previous messageGo to next message
Fadjer is currently offline Fadjer
Messages: 7
Registered: July 2009
Junior Member
Hi,

I'm working since more than 18 months on a RCP application based en Spring an Hibernate. So it possible to implement CRUD operations in an RCP application Wink

Spring 3.0 introduced Spring DM, Spring Dynamic Module to create a Spring application as plugins. It can be intersting for you to check that also ....

For my experience, I'm using Spring 2.5, and I have a separate plugin to manage CRUD operation. This plugins contains all Spring and Hibernate Jars ...

About your example, you should laod the Spring context only once, at start time for example. I noticed that you use FileSystemXmlApplicationContext, instead you should use ClassPathXmlApplicationContext because the Spring file is loaded in memory ...

Good luck
Re: How to implement CRUD operations in an RCP application [message #538749 is a reply to message #534660] Tue, 08 June 2010 14:29 Go to previous message
Martin Lange is currently offline Martin Lange
Messages: 16
Registered: May 2010
Location: Munich, Germany
Junior Member

Hi,

for me it looks like you are missing some jars in your class path. (... caused by java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource ...)

Previous Topic:Looking to outsource an ERCP project
Next Topic:Problem with org.apache.commons.logging while exporting RCP product
Goto Forum:
  


Current Time: Fri Oct 31 05:40:37 GMT 2014

Powered by FUDForum. Page generated in 0.04179 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software