Hi,
I already googled for a few days but all hints i found did not help.
I'm developing an eclipse plugin which uses spring & jpa for database access.
I have a dependency plugin including the following jar files:
spring.jar, spring-aspects.jar, spring-mock.jar, toplink-api.jar, toplink-essentials.jar, commons-logging.jar, ojdbc14.jar
In my plugin project I have an entity class called Users, an Dao interface User and the implementing class which looks like this:
I have two applicationcontext-configuration files,Code:public class UserJpaDaoImpl extends JpaDaoSupport implements UserDao { public UserJpaDaoImpl() { super(); } public List<Users> getUsers(){ return getJpaTemplate().find("select u from Users u"); } }
applicationContext.xml:
and daoApplicationContext.xml: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:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" default-autowire="byName"> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="database.properties"/> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter"> <property name="showSql" value="true"/> <property name="generateDdl" value="false"/> <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.oracle.OraclePlatform"/> </bean> </property> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> <property name="dataSource" ref="dataSource"/> </bean> <tx:annotation-driven/> </beans>
My persistence.xml file looks like this: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:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" default-autowire="byName"> <bean id="userDao" class="mypackage.UserJpaDaoImpl"/> </beans>
In the method void start(BundleContext context) of my plugin Activator class i call the method:Code:<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="SY_PersistenceUnit"> <provider>SY_PersistenceProvider</provider> <class>mypackage.Users</class> </persistence-unit> </persistence>
Now i want to get all Users from Users and just print it out in a view of my plugin. My code looks like this:Code:private void createApplicationContext() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(Activator.class.getClassLoader()); try { this.applicationContext = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml", "daoApplicationContext.xml"); } finally { Thread.currentThread().setContextClassLoader(cl); } }
But now I get a ClassCastException, thrown by the line for(Users u:users) (Cannot cast mypackage.Users to mypackage.Users):Code:ApplicationContext context = Activator.getDefault().getApplicationContext(); UserDao userDao = (UserDao) context.getBean("userDao"); List<Users> users = userDao.getUsers(); for(Users u:users) System.out.println(u.getUsername());
I know that this is a classloader problem. Setting Thread.currentThread().setContextClassLoader(this. getClass().getClassLoader()); won't help in this case.Code:java.lang.ClassCastException: mypackage.Users at com.lhs.ccb.sy.plugin.views.UsersView$ViewContentProvider.initialize(UsersView.java:112) at com.lhs.ccb.sy.plugin.views.UsersView$ViewContentProvider.getElements(UsersView.java:66) ...
It must be a problem with the loadTimeWeaver SimpleLoadTimeWeaver which seems to use a ClassLoader called SimpleInstrumentableClassLoader. But changing the LoadTimeWeaver to one of the two alternatives results in a different error thrown when trying to load my view:
I already tried to add the entries Eclipse-BuddyPolicy: registered and Eclipse-RegisterBuddy: myplugin to my plugin and my dependency plugin, but it made no difference.Code:java.lang.ClassNotFoundException: mypackage.UsersView ...
I don't know what i can do else... I appreciate every suggestion.
Best regards
Matthias


Reply With Quote