I tried to make unit tests with Spring and tests are successfully executed, but my console shows:
1903 [Thread-3] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean 'userDAO': [com.bontade.tests.unit.models.UserDAOTest]
1903 [Thread-3] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean 'userDAO': [com.bontade.tests.unit.models.UserDAOTest]
1904 [Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'userDAO' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
1904 [Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'userDAO' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
1908 [Thread-2] DEBUG org.hibernate.tool.hbm2ddl.SchemaExport - drop table USERS if exists
1908 [Thread-2] DEBUG org.hibernate.tool.hbm2ddl.SchemaExport - drop table USERS if exists
1910 [Thread-2] DEBUG org.hibernate.tool.hbm2ddl.SchemaExport - drop table USER_CAR if exists
1910 [Thread-2] DEBUG org.hibernate.tool.hbm2ddl.SchemaExport - drop table USER_CAR if exists
1910 [Thread-2] INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
1910 [Thread-2] INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
1911 [Thread-3] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean 'org.springframework.transaction.support.TransactionTemplate#831fb31': [userDAO]
1911 [Thread-3] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean 'org.springframework.transaction.support.TransactionTemplate#831fb31': [userDAO]
1912 [Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'org.springframework.transaction.support.TransactionTemplate#831fb31' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:499)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
1912 [Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'org.springframework.transaction.support.TransactionTemplate#831fb31' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.Clas开发者_开发知识库sLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:499)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
1919 [Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'transactionManager' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
1919 [Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'transactionManager' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
1921 [Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'sessionFactory' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
1921 [Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'sessionFactory' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
1923 [Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'dataSource' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
1923 [Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'dataSource' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ CarRentalMaven2XSLTJSPTiles2Tomcat --
How should I fix problem with dataSource bean?
ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'dataSource' threw an exception
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/TransactionRequiredException
My config beans:
<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="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>hibernate/mappings/User.hbm.xml</value>
<value>hibernate/mappings/Car.hbm.xml</value>
<value>hibernate/mappings/Rental.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.characterEncoding">UTF8</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Testing transactional method:
@Test
@Transactional
public void testSaveUser() {
System.out.println("saveUser");
final String name = "xxx",
password = "xxx";
User userTest = new User();
userTest.setId(null);
userTest.setName(name);
userTest.setSurname("xxx");
userTest.setPassword(password);
userTest.setGender("xxx");
userDAO.saveUser(userTest);
User userFromDB = userDAO.getAllUsersByName(name).get(0);
boolean isCorrectPassword = (userFromDB.getPassword()).equals(password);
assertNotNull("should be not null", userFromDB);
assertTrue("wrong password", isCorrectPassword);
}
UPDATE
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
<version>3.3.2.Beta1</version>
</dependency>
I had the same problem, and I figured out because in my pom.xml my Java EE jars are provided by
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
I then deleted the above and changed my Java EE dependencies to the one generated by default by Spring Roo and it solved my problem:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
This problem not related to your code. It looks like you have JPA libraries in the classpath, therefore Spring activates its JPA support (PersistenceAnnotationBeanPostProcessor
), but these libraries are somehow damanged, so that you get java.lang.ClassFormatError
when trying to access them.
Try to find JPA library in your classpath and replace them with the new one.
精彩评论