2011-01-26 56 views
0

我使用jboss5.1.x EJB3.0JPA減速例外

我想用我的JPA第一次,當我運行服務器我得到這個異常:

java.lang.IllegalArgumentException: Can't find a persistence unit named 'java:/mracDS' 

..

這是我的「道」實體,負責對所有的JPA實體:

@Stateless 
    public class ECMSEntityManagerDao implements ECMSEntityManagerDaoLocal, ECMSEntityManagerDaoRemote 
    { 
    @PersistenceContext(unitName = "java:/mracDS") 
    EntityManager em; 


    public ArrayList<T01CounterCalls> getClocksDetailsFromVantive() throws SQLException 
     { 
       return (ArrayList<T01CounterCalls>) em.createQuery ("from T01CounterCalls  as data").getResultList(); 

     } 


    } 

我查了一下在網: 我從來沒有宣佈persistence.xml 如果我這樣做,應該在裏面聲明什麼?

謝謝, 射線。

+0

你已經嘗試過Google嗎? http://www.google.nl/search?persistence.xml – Gerbrand 2011-01-26 20:13:26

回答

2

從它的外觀來看,我的猜測是你把persistence unitdata source搞混了。

這兩個人可能會覺得相似,但他們不是。簡單地說,持久化單元是一組類和一個關聯的數據源。在最基本的形式中,持久性單元僅僅耦合到數據源:

的persistence.xml

<?xml version="1.0" encoding="UTF-8"?> 
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0" 
    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_1_0.xsd"  
>  
    <persistence-unit name="mracPU"> 
     <jta-data-source>java:/mracDS</jta-data-source> 
    </<persistence-unit> 
</persistence> 

然後與注入註釋使用持久性單元名稱:

@Stateless 
public class ECMSEntityManagerDao implements ECMSEntityManagerDaoLocal, ECMSEntityManagerDaoRemote { 

    @PersistenceContext(unitName = "mracPU") 
    EntityManager em; 
}