Hibernate Error – java.lang.NoClassDefFoundError: javax/transaction/Synchronization

Problem

This is caused by missing of the “jta.jar“, usually happened in Hibernate transaction development.


java.lang.NoClassDefFoundError: javax/transaction/Synchronization
 at org.hibernate.impl.SessionImpl.<init>(SessionImpl.java:213)
 at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:473)
 at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:497)
 at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:505)
 at com.mkyong.common.App.main(App.java:13)
Caused by: java.lang.ClassNotFoundException: javax.transaction.Synchronization
 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 java.lang.ClassLoader.loadClassInternal(Unknown Source)
 ... 5 more

Solution

You can download “jta.jar” from default Maven central, JBoss or Java.net repositories.

1. Maven central repository


   <dependencies>
        <dependency>
		<groupId>javax.transaction</groupId>
		<artifactId>jta</artifactId>
		<version>1.1</version>
	</dependency>
   </dependencies>

2. JBoss Maven repository

Add JBoss Maven repository


	<repositories>
		<repository>
			<id>JBoss repository</id>
			<url>http://repository.jboss.com/maven2/</url>
		</repository>
	</repositories>

and define “jta.jar” detail.


	<dependencies>
		<dependency>
			<groupId>javax.transaction</groupId>
			<artifactId>jta</artifactId>
			<version>1.1</version>
		</dependency>
	</dependencies>

3. Java net Maven repository

Add Java net Maven repository


	<repositories>
		<repository>
			<id>Java 2</id>
			<url>http://download.java.net/maven/2/</url>
		</repository>
	</repositories>

and define “ jta1.0.1B.jar” detail.


	<dependencies>
		<dependency>
			<groupId>javax.transaction</groupId>
			<artifactId>jta</artifactId>
			<version>1.0.1B</version>
		</dependency>
	</dependencies>
Note
Alternately, you can include the “javaee.jar“, which can be found under J2EE SDK’s folder. The “javaee.jar” contains “javax/transaction/Synchronization” class as well.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
5 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
5 Comment authors
Gabriel TeodósioMateenasdfsamandesperatedCoder Recent comment authors
newest oldest most voted
Gabriel Teodósio
Guest
Gabriel Teodósio

Thanks a lot mkyong, you just saved my life with that precise and objective solucion.

Mateen
Guest
Mateen

thanks for the knowledege

asdf
Guest
asdf

Thanks, very objective e precise.

saman
Guest
saman

heeey mkong your perfect
tnk u aloot (Y)

desperatedCoder
Guest
desperatedCoder

Thanks a lot