2013-07-21 65 views
0

我想在JBoss AS中7.1.1JBoss作爲7 Hibernate配置

配置Hibernate。我只會把WEB-INF文件夾

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

OB中的persistence.xml:JBOSS 7.1.1有一個休眠4模塊和我有一個數據源命名的java:/ ActionBazaarDS

,但我得到這個錯誤:

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

當我嘗試使用:

web.xml上
@PersistenceContext(unitName="actionBazaar") 
private EntityManager entityManager; 
+1

你試過WEB-INF /班/ META-INF/persistence.xml中? – jjhavokk

+0

我也試過,但沒有成功 –

+0

請按照此鏈接 [鏈接] http://stackoverflow.com/questions/14060051/how-to-configure-hibernate-in-j-boss/21159460#21159460 –

回答

0

設置以下設置

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

這將導致你的persistence.xml到JBoss中該名稱下

0

您正在嘗試發佈使用jboss 7.1.1配置休眠,如果您使用的是MySQL數據庫,請從以下答案開始:How to configure Hibernate in JBoss

您的休眠配置是用jboss 7.1.1完成。

之後部署projetc ....

如果在部署你的項目,然後添加一個類項目 也就是說類HibernateUtil.java並提供持久性單元名稱未發生的錯誤的EntityManager持久化提供者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; 
    } 

}