1 2 3 Previous Next 30 Replies Latest reply on Dec 1, 2011 6:19 AM by jilani2423 Go to original post
      • 30. Re: naming context read only while creating hibernate session
        jilani2423

        I have faced problem while getting the hibernate session, So as suggested by Scott I have tried for EntityManager to work with database for persistence.

         

        With below entries in persistence.xml, I am able to get the EntityManager Object

         

        <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 ">

          <persistence-unit name="ldm_pu">

              <provider>org.hibernate.ejb.HibernatePersistence</provider> 

              <jta-data-source>java:/ldmDS</jta-data-source> 

              <properties>

                 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />

                 <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />

              </properties>

          </persistence-unit>

        </persistence>

         

        The code which I used for getting session using entity manager is as follows

         

                EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("ldm_pu");

                EntityManager em = emf.createEntityManager();

                Session session = (Session)em.unwrap(Session.class);

         

        Using this approach I am able to proceed for persistence of information using JPA.

         

         

        Thank You,

        Jilani

        1 2 3 Previous Next