Help with spring

Discussions

General J2EE: Help with spring

  1. Help with spring (1 messages)

    Hello i'm following this tutorial Introduction to Spring 2 and JPA from IBM and when I try to run EmployeeServiceIntegrationTest.class as a JUnit test i'm getting an error i cant get rid of. Here are the files Employee.class @Entity public class Employee { @Id @GeneratedValue(strategy = GenerationType.TABLE) private long empid; @Column(length = 6) private String empno; @Column(name = "FIRSTNME") private String firstName; HERE ALL THE VARIABLES, GETTERS AND SETTERS public Employee(String empno, String firstName, String midInitial, String lastName, String phoneNumber, String job, int educationLevel, char sex, double salary, double bonus, double commission, Address addr, Date hiredate, Date birthdate) { this.empno = empno; this.firstName = firstName; this.midInitial = midInitial; this.lastName = lastName; this.phoneNumber = phoneNumber; this.job = job; this.educationLevel = educationLevel; this.sex = sex; this.salary = salary; this.bonus = bonus; this.commission = commission; this.addr = addr; this.hiredate = hiredate; this.birthdate = birthdate; } public Employee() {} } EmploeeService.class public interface EmployeeService { // create a new employee public Employee save(Employee emp); // removing an employee public void delete(Employee emp); // update the information on an employee public Employee update(Employee emp); // find all the employees in the company public List findAll(); // find an employee by the employee number public List findByEmployeeNumber(String empno); // find an employee by his name public List findByEmployeeLastName(String lastName); // find an employees living on a street public List findByAddressStreetName(String streetName); // find an employee by the internal unique id public Employee findById(long id); // find employee over a certain salary public List findEmployeeWithSalaryOver(double sal); // find employee with a certain commission income public List findEmployeeWithCommissionOver(double comm); } EmployeeDAO.class public class EmployeeDAO extends JpaDaoSupport implements EmployeeService { public Employee findById(long id) { return getJpaTemplate().find(Employee.class, id); } public List findAll() { return getJpaTemplate().find("select e from Employee e"); } public List findByEmployeeNumber(String empno) { return getJpaTemplate().find("select e from Employee e where e.empno = ?1", empno); } public List findByAddressStreetName(String street) { return getJpaTemplate().find("select e from Employee e where e.addr.street = ?1", street); } public List findByEmployeeLastName(String lastName) { return getJpaTemplate().find("select e from Employee e where e.lastName = ?1", lastName); } public List findEmployeeWithSalaryOver(double sal) { return getJpaTemplate().find("select e from Employee e where e.salary > ?1", sal); } public List findEmployeeWithCommissionOver(double comm) { return getJpaTemplate().find("select e from Employee e where e.commission > ?1", comm); } public Employee save(Employee emp) { getJpaTemplate().persist(emp); return emp; } public Employee update(Employee emp) { return getJpaTemplate().merge(emp); } public void delete(Employee emp) { getJpaTemplate().remove(emp); } } EmployeeServiceIntegrationTest.class public class EmployeeServiceIntegrationTest extends AbstractJpaTests { private EmployeeService employeeService; private long JoeSmithId = 99999; public void setEmployeeService(EmployeeService employeeService) { this.employeeService = employeeService; } protected String[] getConfigLocations() { return new String[] { "classpath:/com/ibm/dw/spring2/dwspring2-service.xml" }; } protected void onSetUpInTransaction() throws Exception { Employee emp1 = new Employee("0001", "Joe", "R","Smith", "4853", "Engineer", 3, 'M', 20000.00, 0.00, 0.00, new Address(10, "Walker Street") , new Date(), new Date()); Employee emp2 = new Employee("0002", "John","T","Lockheed", "4333", "Sales", 2, 'M', 40000.00, 0.00, 5000.00, new Address(20, "Walker Street") , new Date(), new Date()); Employee emp3 = new Employee("0003", "Mary","M","Johnson", "4383", "Admin", 3, 'F', 60000.00, 0.00, 390.00, new Address(123, "Booth Ave") , new Date(), new Date()); employeeService.save(emp1); employeeService.save(emp2); employeeService.save(emp3); JoeSmithId = emp1.getEmpid(); } public void testFindByEmployeeId() { Employee emp = employeeService.findById(JoeSmithId); assertNotNull(emp); assertEquals("Joe", emp.getFirstName()); } public void testFindByEmployeeIdBadId() { Employee emp = employeeService.findById(99999); assertNull(emp); } public void testFindByEmployeeNum() { List emps = employeeService.findByEmployeeNumber("0002"); assertEquals(1, emps.size()); Employee emp = emps.get(0); assertEquals("John", emp.getFirstName()); } public void testFindByEmployeeNumBadNum() { List emps = employeeService.findByEmployeeNumber("0099"); assertEquals(0, emps.size()); } public void testFindByLastName() { List emps = employeeService.findByEmployeeLastName("Johnson"); assertEquals(1, emps.size()); Employee emp = emps.get(0); assertEquals("0003", emp.getEmpno()); } public void testFindByNameWhereRestaurantDoesNotExist() { List emps = employeeService.findByEmployeeLastName("Higgins"); assertEquals(0, emps.size()); } public void testFindByStreetName() { List emps = employeeService.findByAddressStreetName("Walker Street"); assertEquals(2, emps.size()); } public void testFindByStreetNameBadName() { List emps = employeeService.findByAddressStreetName("Yonge Street"); assertEquals(0, emps.size()); } public void testFindBySalary() { List emps = employeeService.findEmployeeWithSalaryOver(50000.00); assertEquals(1, emps.size()); } public void testFindBySalaryOutOfRange() { List emps = employeeService.findEmployeeWithSalaryOver(80000.00); assertEquals(0, emps.size()); } public void testFindByCommission() { List emps = employeeService.findEmployeeWithCommissionOver(1000.00); assertEquals(1, emps.size()); } public void testFindByCommissionOutOfRange() { List emps = employeeService.findEmployeeWithCommissionOver(8000.00); assertEquals(0, emps.size()); } public void testModifyEmployee() { String oldLastName = "Lockheed"; String newLastName = "Williams"; Employee emp = employeeService.findByEmployeeLastName(oldLastName).get(0); emp.setLastName(newLastName); Employee emp2 = employeeService.update(emp); assertEquals(newLastName, emp2.getLastName()); List results = employeeService.findByEmployeeLastName(oldLastName); assertEquals(0, results.size()); results = results = employeeService.findByEmployeeLastName(newLastName); assertEquals(1, results.size()); } public void testDeleteEmployeeCascade() { String empName = "Lockheed"; Employee emp = employeeService.findByEmployeeLastName(empName).get(0); int empCountBefore = countRowsInTable("employee"); int addrCountBefore = countRowsInTable("address"); employeeService.delete(emp); List res = employeeService.findByEmployeeLastName(empName); assertEquals(0, res.size()); int empCountAfter = countRowsInTable("employee"); int addrCountAfter = countRowsInTable("address"); assertEquals(empCountBefore -1, empCountAfter); assertEquals(addrCountBefore -1, addrCountAfter); } public void testFindAll() { List emps = employeeService.findAll(); assertEquals(3, emps.size()); } } dwspring2-service.xml <!--?xml version="1.0" encoding="UTF-8"?--> <!-- <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.DB2Platform"/> --> <!-- <property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/> --> <!-- <property name="url" value="jdbc:db2://192.168.23.36:50000/dwspring"/> <property name="url" value="jdbc:hsqldb:hsql://localhost/dwspring" /> --> Well, as i sad before when i try to run the JUnit test on EmployeeServiceIntegrationTest.class i get the following error org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeService' defined in class path resource [com/ibm/dw/spring2/dwspring2-service.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/ibm/dw/spring2/dwspring2-service.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.instrument.classloading.ResourceOverridingShadowingClassLoader.addTransformers(Lorg/springframework/instrument/classloading/ShadowingClassLoader;)V at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1244) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:217) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:216) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/ibm/dw/spring2/dwspring2-service.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.instrument.classloading.ResourceOverridingShadowingClassLoader.addTransformers(Lorg/springframework/instrument/classloading/ShadowingClassLoader;)V at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1336) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:217) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269) ... 32 more Caused by: java.lang.NoSuchMethodError: org.springframework.instrument.classloading.ResourceOverridingShadowingClassLoader.addTransformers(Lorg/springframework/instrument/classloading/ShadowingClassLoader;)V at org.springframework.test.jpa.AbstractJpaTests$ShadowingLoadTimeWeaver.getThrowawayClassLoader(AbstractJpaTests.java:334) at org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getNewTempClassLoader(SpringPersistenceUnitInfo.java:87) at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:531) at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createContainerEntityManagerFactory(EntityManagerFactoryProvider.java:178) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:227) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:273) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333) ... 42 more I hope some1 can help me out because i'm going crazy right now :P thanks in advance
  2. persistence.xml & JPA implementation?[ Go to top ]

    persistence.xml & JPA implementation?