title: Hibernate & Spring: Exception when trying to create a transaction
body: <p>So I'm trying to use Spring to manage hibernate transactions for the first time, and something's going wrong. I'm not sure what. I've looked at a bunch of similar answers on this site and nothing I've seen seems to be right.</p>
  
  <p>So, I'm gonna copy and paste a bunch of my code with some explanations and ask for help here.</p>
  
  <p>Here is a stack trace of the exception I'm getting. Essentially, It seems that it's trying to find org.hibernate.engine.transaction.spi.transactioncontext, and can't.</p>
  
  <p>Exception stack trace</p>
  
  <pre><code>EXCEPTION: Could not open Hibernate Session for transaction; nested exception is java.lang.NoClassDefFoundError: org/hibernate/engine/transaction/spi/TransactionContext
  org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:544)
  org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
  org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:427)
  org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)
  org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
  org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
  org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
  com.sun.proxy.$Proxy42.getSavedPortfolios(Unknown Source)
  io.craigmiller160.stockmarket.controller.StockMarketController.showOpenPortfolioDialog(StockMarketController.java:994)
  io.craigmiller160.stockmarket.controller.StockMarketController.parseEvent(StockMarketController.java:431)
  io.craigmiller160.stockmarket.controller.StockMarketController.processEvent(StockMarketController.java:336)
  io.craigmiller160.mvp.concurrent.AbstractConcurrentListenerController$1.run(AbstractConcurrentListenerController.java:209)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>Now, I've searched this site, and the big thing I saw was that this means I have a dependency wrong in my pom.xml. The thing is, I have the most up-to-date version of the hibernate-core dependency in my pom. From what I've read, that's what I need for this class.</p>
  
  <p>pom.xml dependencies</p>
  
  <pre><code>&lt;dependencies&gt;
  &lt;!-- JUnit Testing --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;4.12&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  &lt;!-- MVP Framework --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.craigmiller160.mvp&lt;/groupId&gt;
          &lt;artifactId&gt;mvp-framework&lt;/artifactId&gt;
          &lt;version&gt;2.1.1&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- MigLayout --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.miglayout&lt;/groupId&gt;
          &lt;artifactId&gt;miglayout-swing&lt;/artifactId&gt;
          &lt;version&gt;5.0&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- JFreeChart --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jfree&lt;/groupId&gt;
          &lt;artifactId&gt;jfreechart&lt;/artifactId&gt;
          &lt;version&gt;1.0.19&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Java Concurrency In Practice Annotations --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;net.jcip&lt;/groupId&gt;
          &lt;artifactId&gt;jcip-annotations&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Joda Time --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;joda-time&lt;/groupId&gt;
          &lt;artifactId&gt;joda-time&lt;/artifactId&gt;
          &lt;version&gt;2.8.2&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- MySQL ConnectorJ --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.36&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Spring Framework Core --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Spring Framework Beans --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Spring Framework Context --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Hibernate Core --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.0.1.Final&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- XML Framework --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;dom4j&lt;/groupId&gt;
          &lt;artifactId&gt;dom4j&lt;/artifactId&gt;
          &lt;version&gt;1.6.1&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Code Generation library --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;cglib&lt;/groupId&gt;
          &lt;artifactId&gt;cglib&lt;/artifactId&gt;
          &lt;version&gt;3.1&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Apache Commons Logging --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-logging&lt;/groupId&gt;
          &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- LOG4J API --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
          &lt;version&gt;${log4j.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- LOG4J Core --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
          &lt;version&gt;${log4j.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- SLF4J/LOG4J Binding --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-slf4j-impl&lt;/artifactId&gt;
          &lt;version&gt;${log4j.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- LOG4J/Commons Logging Binding --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-jcl&lt;/artifactId&gt;
          &lt;version&gt;${log4j.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- SLF4J API --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
          &lt;version&gt;1.7.12&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Spring ORM --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- AspectJ Runtime --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
          &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
          &lt;version&gt;${aspectj.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- AspectJ Weaver --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
          &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
          &lt;version&gt;${aspectj.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;!-- Apache Database Connection Pooling --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
          &lt;artifactId&gt;commons-dbcp2&lt;/artifactId&gt;
          &lt;version&gt;2.1.1&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>Also, I'm adding the actual method in my DAO that I'm calling. This method is what is attempting to run when the exception is thrown.</p>
  
  <p>DAO method:</p>
  
  <pre><code>@Transactional
  @Override
  @SuppressWarnings("unchecked") //hibernate list() method doesn't support generics
  public List&lt;String&gt; getSavedPortfolios() throws HibernateException {
      List&lt;String&gt; portfolioNames = new ArrayList&lt;&gt;();
  
      List&lt;SQLPortfolioModel&gt; portfolioList = sessionFactory.getCurrentSession()
                                  .createCriteria(PortfolioModel.class)
                                  .list();
  
      for(SQLPortfolioModel portfolio : portfolioList){
          int id = portfolio.getUserID();
          String name = portfolio.getPortfolioName();
          BigDecimal netWorth = portfolio.getNetWorth();
          Calendar timestamp = portfolio.getTimestamp();
  
          String fileName = String.format("%1$d-%2$s-%3$s-"
                  +"%4$s", id, name, moneyFormat.format(netWorth), 
                  timestampFormat.format(timestamp.getTime()));
          portfolioNames.add(fileName);
      }
  
      return portfolioNames;
  }
  </code></pre>
  
  <p>Lastly, here is my spring-context-data.xml. It contains all the configuration for my data beans for spring, plus the transaction stuff:</p>
  
  <p>spring-context-data.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
  &lt;!-- Sets annotation-driven transactions --&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
  &lt;!-- DataSource object for providing database connections --&gt;
  &lt;bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="url" value="jdbc:mysql://localhost/stockmarket"/&gt;
      &lt;property name="username" value="stockmarket"/&gt;
      &lt;property name="password" value="stockmarket"/&gt;
  &lt;/bean&gt;
  
  &lt;!-- SessionFactory object for creating sessions for database access --&gt;
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;!-- &lt;property name="configLocation" value="classpath:hibernate.cfg.xml"/&gt;--&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
              &lt;prop key="connection.pool_size"&gt;1&lt;/prop&gt;
              &lt;prop key="show_sql"&gt;false&lt;/prop&gt;
              &lt;!-- Might need this one below for transactions, not sure yet --&gt;
              &lt;prop key="hibernate.transaction.factory_class"&gt;org.hibernate.transaction.JDBCTransactionFactory&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
      &lt;property name="annotatedClasses"&gt;
          &lt;list&gt;
              &lt;value&gt;io.craigmiller160.stockmarket.stock.AbstractStock&lt;/value&gt;
              &lt;value&gt;io.craigmiller160.stockmarket.stock.OwnedStock&lt;/value&gt;
              &lt;value&gt;io.craigmiller160.stockmarket.stock.DefaultStock&lt;/value&gt;
              &lt;value&gt;io.craigmiller160.stockmarket.stock.DefaultOwnedStock&lt;/value&gt;
              &lt;value&gt;io.craigmiller160.stockmarket.model.PortfolioModel&lt;/value&gt;
              &lt;value&gt;io.craigmiller160.stockmarket.model.SQLPortfolioModel&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Hibernate Transaction Manager --&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;!-- HibernateDAO class for performing database operations --&gt;
  &lt;bean id="hibernateDao" class="io.craigmiller160.stockmarket.controller.HibernatePortfolioDAO"
      destroy-method="closeFactory"&gt;
      &lt;constructor-arg ref="sessionFactory"/&gt;
  &lt;/bean&gt;
  
   &lt;/beans&gt;
  </code></pre>
  
  <p>So I just have no idea why this is happening. I've double and triple checked what I did versus what I'm seeing online, and I can't see the mistake. This is my first time trying to use Spring transaction management. Any help would be greatly appreciated.</p>
  
  <p>PS. I'm using Spring 4 &amp; Hibernate 5 together, if that makes a difference.</p>