title: Access sessionFactory using Jboss Jndi lookup e.g. java:/hibernate/SessionFactory
body: <p>I'm trying to access sessionFactory using Jboss7.1.1.Final Jndi lookup under maven.</p>
  
  <p>While deploying it I'm getting in log following</p>
  
  <pre><code>17:28:33,670 INFO  [org.hibernate.cfg.Configuration] (http-localhost-127.0.0.1-8080-1) configuring from resource: /hibernate.cfg.xml
  17:28:33,671 INFO  [org.hibernate.cfg.Configuration] (http-localhost-127.0.0.1-8080-1) Configuration resource: /hibernate.cfg.xml
  17:28:34,026 INFO  [org.hibernate.cfg.Configuration] (http-localhost-127.0.0.1-8080-1) Configured SessionFactory: java:/hibernate/SessionFactory
  
  17:28:35,785 INFO  [org.hibernate.impl.SessionFactoryImpl] (http-localhost-127.0.0.1-8080-1) building session factory
  17:28:36,535 INFO  [org.hibernate.impl.SessionFactoryObjectFactory] (http-localhost-127.0.0.1-8080-1) Factory name: java:/hibernate/SessionFactory
  17:28:36,537 INFO  [org.hibernate.util.NamingHelper] (http-localhost-127.0.0.1-8080-1) JNDI InitialContext properties:{}
  
  17:28:36,546 INFO  [org.hibernate.impl.SessionFactoryObjectFactory] (http-localhost-127.0.0.1-8080-1) Bound factory to JNDI name: java:/hibernate/SessionFactory
  </code></pre>
  
  <p>Now at time of casting using following code</p>
  
  <pre><code>Context ctx1=new InitialContext();
  Object obj1=ctx1.lookup("java:/hibernate/SessionFactory");
  SessionFactoryImpl sess= (SessionFactoryImpl)obj1;
  </code></pre>
  
  <p>I'm getting exception as follows</p>
  
  <pre><code>17:28:36,691 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) java.lang.ClassCastException: org.hibernate.impl.SessionFactoryImpl cannot be cast to org.hibernate.impl.SessionFactoryImpl
  </code></pre>
  
  <p>Dependency I'm using for this is </p>
  
  <pre><code>&lt;dependency&gt;
  &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
  &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
  &lt;version&gt;4.0.1.Final&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>and my xml is</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory name="java:/hibernate/SessionFactory"&gt;
      &lt;property name="connection.url"&gt;jdbc:postgresql://localhost:5432/DUMY&lt;/property&gt;
      &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
      &lt;property name="connection.username"&gt;postgres&lt;/property&gt;
      &lt;property name="connection.password"&gt;postgres&lt;/property&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt;        
  
      &lt;property name="hibernate.session_factory_name"&gt;java:/hibernate/SessionFactory&lt;/property&gt;          
      .
      .
      .
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;  
  </code></pre>
  
  <p>Please Help.</p>