title: Received :org.springframework.transaction.CannotCreateTransactionException
body: <p>I am making a JPA application in eclipse.I have designed the service layer with spring.I have 
  used "HibernatePersistence" as persistence provider.
  Below is my persistence layer:</p>
  
  <pre><code>    @MappedSuperclass
      public class BaseEntity implements Serializable{
  
      /**
       * 
       */
      @Transient
      private static final long serialVersionUID = -2265881632984808864L;
  
     @Id
     @GeneratedValue(strategy=GenerationType.IDENTITY)
     @Column(name="ID",nullable=false,updatable=false)
     private Long id;
     /**
     * @return the id
     */
     public Long getId() {
      return id;
      }
     /**
      * @param id the id to set
     */
     public void setId(Long id) {
      this.id = id;
    }
   }
  
  package com.edfx.jpapp.persist.entity;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Table;
  import javax.persistence.Transient;
  
  @Entity
  @Table(name = "Customer", schema = "customerdb")
  public class Customer extends BaseEntity {
  
  /**
   * 
   */
  @Transient
  private static final long serialVersionUID = 1443119926544372161L;
  
  @Column(name = "CUSTOMER_NAME", nullable = false, length = 30)
  private String customerName;
  @Column(name = "CUSTOMER_ADDRESS", nullable = false, length = 25)
  private String customerAddress;
  
  /**
   * @return the customerName
   */
  public String getCustomerName() {
      return customerName;
  }
  
  /**
   * @param customerName
   *            the customerName to set
   */
  public void setCustomerName(String customerName) {
      this.customerName = customerName;
  }
  
  /**
   * @return the customerAddress
   */
  public String getCustomerAddress() {
      return customerAddress;
  }
  
  /**
   * @param customerAddress
   *            the customerAddress to set
   */
  public void setCustomerAddress(String customerAddress) {
      this.customerAddress = customerAddress;
  }
  
  /**
   * @return the serialversionuid
   */
  public static long getSerialversionuid() {
      return serialVersionUID;
  }
    }
  </code></pre>
  
  <p>here is my DAO layer</p>
  
  <pre><code>package com.edfx.dao.impl;
  
  import java.util.List;
  
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  
  import com.edfx.jpapp.dao.CustomerDAO;
  import com.edfx.jpapp.persist.entity.Customer;
  
  public class CustomerDAOImpl implements CustomerDAO {
  
   @PersistenceContext(unitName="customerUnit")
    private EntityManager entityManager;
  
  /**
   * @return the entityManager
   */
    public EntityManager getEntityManager() {
      return entityManager;
    }
  
  /**
   * @param entityManager
   *            the entityManager to set
    */
    public void setEntityManager(EntityManager entityManager) {
      this.entityManager = entityManager;
    }
  
    @Override
    public void insertCustomer(Customer customer) {
      entityManager.persist(customer);
     }
  
     @Override
     public List&lt;Customer&gt; getAllCustomer() {
  
      return entityManager.createQuery("select c from customer c",
              Customer.class).getResultList();
      }
      }
  
  
   here is the service layer
  
  package com.edfx.jpapp.service.impl;
  
  import java.util.ArrayList;
  import java.util.List;
  import org.dozer.Mapper;
  import org.springframework.transaction.annotation.Propagation;
  import org.springframework.transaction.annotation.Transactional;
  import com.edfx.jpapp.dto.CustomerDTO;
  import com.edfx.jpapp.persist.entity.Customer;
  import com.edfx.jpapp.service.CustomerService;
  import com.edfx.jpapp.service.base.BaseService;
  
   @Transactional
   public class CustomerServiceImpl extends BaseService implements CustomerService {
  
  @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = { Throwable.class })
  @Override
  public void insertCustomer(CustomerDTO customerDTO) {
      Customer customer = getBeanMapper().map(customerDTO, Customer.class);
      getDaoProvider().getCustomerDAO().insertCustomer(customer);
  }
  
  @Transactional(readOnly = true)
  @Override
  public List&lt;CustomerDTO&gt; getAllCustomer() {
      Mapper mapper = getBeanMapper();
      ArrayList&lt;CustomerDTO&gt; customerDTOs = new ArrayList&lt;CustomerDTO&gt;();
      List&lt;Customer&gt; customers = getDaoProvider().getCustomerDAO()
              .getAllCustomer();
      for (Customer customer : customers) {
          CustomerDTO customerDTO = mapper.map(customer, CustomerDTO.class);
          customerDTOs.add(customerDTO);
      }
      return customerDTOs;
  }
   }
  </code></pre>
  
  <p>I have placed my persistence.xml file under META-INF Folder: and it is as follows</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="UTF-8"?&gt;
     &lt;persistence version="2.0"
  xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
   &lt;persistence-unit name="customerUnit"
      transaction-type="JTA"&gt;
       &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
       &lt;jta-data-source&gt;java:/jBossCustomerMysql&lt;/jta-data-source&gt;
       &lt;class&gt;com.edfx.jpapp.persist.entity.Customer&lt;/class&gt;
       &lt;validation-mode&gt;NONE&lt;/validation-mode&gt;
       &lt;properties&gt;
           &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
       &lt;/properties&gt;
   &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>I have used JTA DataSource and I have configured the JNDI in jboss standalone.xml file 
    as follows:</p>
  
  <pre><code>         &lt;datasource jta="true" jndi-name="java:/jBossCustomerMysql" pool-name="jBossCustomerMysql" enabled="true" use-ccm="false"&gt;
                  &lt;connection-url&gt;jdbc:mysql://localhost:3306/customerdb&lt;/connection-url&gt;
                  &lt;driver-class&gt;com.mysql.jdbc.Driver&lt;/driver-class&gt;
                  &lt;driver&gt;mysql&lt;/driver&gt;
                  &lt;security&gt;
                      &lt;user-name&gt;root&lt;/user-name&gt;
                      &lt;password&gt;root&lt;/password&gt;
                  &lt;/security&gt;
                  &lt;validation&gt;
                      &lt;validate-on-match&gt;false&lt;/validate-on-match&gt;
                      &lt;background-validation&gt;false&lt;/background-validation&gt;
                  &lt;/validation&gt;
                  &lt;statement&gt;
                      &lt;share-prepared-statements&gt;false&lt;/share-prepared-statements&gt;
                  &lt;/statement&gt;
              &lt;/datasource&gt;
  </code></pre>
  
  <p>well when I ran the application my Tables got created in database.But when I try to insert a customer from xhtml page then I got the exception::</p>
  
  <pre><code>13:52:37,227 SEVERE [javax.faces.event] (http-localhost-127.0.0.1-8087-2) Received 'org.springframework.transaction.CannotCreateTransactionException' when invoking action  listener '#{customerController.addCustomer}' for component 'j_idt9'
  13:52:37,227 SEVERE [javax.faces.event] (http-localhost-127.0.0.1-8087-2) org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NullPointerException
   at  org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:329)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
  at com.sun.proxy.$Proxy22.insertCustomer(Unknown Source)
  at com.edfx.jpapp.web.controller.CustomerController.addCustomer(CustomerController.java:56)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:601)
  at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
  at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
  at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
  at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148)
  at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
  at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
  </code></pre>
  
  <p>Below is my spring configuration file:</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"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;
  
   &lt;bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceUnitName" value="customerUnit" /&gt;
      &lt;property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /&gt;
      &lt;property name="packagesToScan" value="com.edfx.jpapp.persist.entity" /&gt;
    &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>anther one is transactionConfig.xml file:</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-3.1.xsd"&gt;
  
   &lt;bean id="transactionInterceptor" abstract="true"
       class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;
      &lt;property name="transactionManager" ref="transactionManager" /&gt;
      &lt;property name="transactionAttributeSource"&gt;
      &lt;bean           class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" /&gt;
        &lt;/property&gt;
        &lt;/bean&gt;
  
       &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
         &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
       &lt;/bean&gt;
    &lt;/beans&gt;
  </code></pre>
  
  <p>can anyone give any solution to this??????</p>