title: An application using EJB 3.0 and Hibernate persistence provider gives an UnknownServiceException
body: <p>I am trying to create a web app using JSF and EJB 3.0.</p>
  
  <p>I am using plain JSF, Glassfish Server, Hibernate as my persistance provider. My database is apache derby.</p>
  
  <p>Here my Stateless Session bean as follows:</p>
  
  <pre><code>  @Stateless
    @TransactionManagement(TransactionManagementType.CONTAINER)
    public class StudentServiceBean implements StudentService{
  
  
      @PersistenceContext(unitName="forPractise")
      private EntityManager entityMgr;
  
      @Resource
      private SessionContext sessionContext;
  
      @Override
      public List&lt;StudentVO&gt; fetchStudentListOrderByStudentId(boolean flag){
          List&lt;StudentEntity&gt; studentList = null;
          TypedQuery&lt;StudentEntity&gt; studentQuery = null; 
          List&lt;StudentVO&gt; studentVOList = null;
          String queryDesc = "select s from StudentEntity s order by s.studentId desc";
          String query = "select s from StudentEntity s order by s.studentId";
          try{
  
              if(!flag){
                  studentQuery = entityMgr.createQuery(query,StudentEntity.class);
              }else{
                  studentQuery = entityMgr.createQuery(queryDesc,StudentEntity.class);
              }           
  
              studentList = studentQuery.getResultList();
              studentVOList = new ArrayList&lt;StudentVO&gt;();
              for(StudentEntity studentE : studentList){              
                  studentVOList.add(new StudentVO(String.valueOf(studentE.getStudentId()),studentE.getStudentName(),studentE.getContactNumber()));
              }
  
          }catch(Exception e){
              System.out.println(" EXCEPTION IN "+this.getClass().getName()+" in method fetchStudentListOrderByStudentId "+e);
          }
          return studentVOList;
      }
  </code></pre>
  
  <p>And this is my persistence.xml:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;persistence 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"
                version="2.0"&gt;
      &lt;persistence-unit name="forPractise" transaction-type="JTA"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;jta-data-source&gt;jdbc/app&lt;/jta-data-source&gt;
          &lt;class&gt;com.entity.StudentEntity&lt;/class&gt;
          &lt;properties&gt;
                  &lt;property name="hibernate.dialect"  value="org.hibernate.dialect.DerbyDialect"  /&gt;
                  &lt;property name="hibernate.show_sql" value="true" /&gt;
                  &lt;property name="hibernate.format_sql" value="true" /&gt;               
                  &lt;property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup" /&gt;             
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
   &lt;/persistence&gt;
  </code></pre>
  
  <p>What happens is on load of the JSP page, the getter method of StudentList is called -
  inside the getter method I have written logic that if <code>studentList</code> is empty then call the <code>studentService.fetchStudentListOrderByStudentId(true);</code>.</p>
  
  <p>But when I do this I get an exception:</p>
  
  <blockquote>
    <p>EXCEPTION IN com.bb.StudentServiceBean in method
    fetchStudentListOrderByStudentId
    org.hibernate.service.UnknownServiceException: Unknown service
    requested
    [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]</p>
  </blockquote>
  
  <p>Can you please tell me what I am missing, or where I am going wrong?</p>
  
  <p>Thanks.</p>