0

I'm trying to configure hibernate in JBOSS AS 7.1.1

I only put the persistence.xml in WEB-INF folder

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="actionBazaar" transaction-type="JTA">
   <provider>org.hibernate.ejb.HibernatePersistence</provider>
   <jta-data-source>java:/ActionBazaarDS</jta-data-source>
   <properties>
      <property name="hibernate.show_sql" value="true" />
   </properties>
</persistence-unit>
</persistence>

Obs: JBOSS 7.1.1 have a module with a hibernate 4 and i have a DataSource named java:/ActionBazaarDS

But i get this error:

Can't find a persistence unit named actionBazaar in deployment "ActionBazaar.war"

When i try use:

@PersistenceContext(unitName="actionBazaar")
private EntityManager entityManager;
Wilker Iceri
  • 669
  • 1
  • 6
  • 5

2 Answers2

0

Setup following settings on web.xml

<persistence-unit-ref>
  <persistence-unit-ref-name>persistence/actionBaazar</persistence-unit-ref-name>
  <persistence-unit-name>actionBazaar</persistence-unit-name>
</persistence-unit-ref>

It will cause your persistence.xml to be published in JBoss under that name

gerrytan
  • 40,313
  • 9
  • 84
  • 99
0

You are trying to configure hibernate with jboss 7.1.1 and if you are using MySQL database, start by following this answer: How to configure Hibernate in JBoss

Your hibernate configuration is done with jboss 7.1.1.

After that deploy your projetc....

If No Persistence provider for EntityManager Error occurred while deploying your project then add one class in your project That is class HibernateUtil.java and provide the persistence unit name to entityManagerFactory = Persistence.createEntityManagerFactory("abc");

public class HibernateUtil {

    private static final EntityManagerFactory entityManagerFactory;
    static {
                try {
                     entityManagerFactory = Persistence.createEntityManagerFactory("abc");
                     System.out.println("Entity Menager Test.............."+ entityManagerFactory);
                } catch (Throwable ex) {

                    System.err.println("Initial SessionFactory creation failed." + ex);
                    throw new ExceptionInInitializerError(ex);

                  }
    }

public static EntityManagerFactory getEntityManagerFactory() {
         return entityManagerFactory;
    }

}
Community
  • 1
  • 1
Ujwal Daware
  • 373
  • 5
  • 18