2013-05-30 86 views
4

中可用我試圖在使用EJB 3.1,JPA 2.0,M2E-WTP和JSF 2.1技術的weblogic 12c服務器上運行我的webapp,並繼續得到以下錯誤:Webapp找不到持久性單元。沒有名爲'X'的持久性單元在範圍

javax.ejb.EJBException: EJB 
Exception: : java.lang.IllegalArgumentException: No persistence unit named 'X' 
is available in scope Webapp. Available persistence units: [] at 
weblogic.persistence.ModulePersistenceUnitRegistry 
.getPersistenceUnit(ModulePersistenceUnitRegistry.java:130) at 
weblogic.persistence.BasePersistenceContextProxyImpl 
.<init>(BasePersistenceContextProxyImpl.java:40) at 
weblogic.persistence.TransactionalEntityManagerProxyImpl 
.<init>(TransactionalEntityManagerProxyImpl.java:31) at 
weblogic.persistence.EntityManagerInvocationHandlerFactory. 
createTransactionalEntityManagerInvocationHandler 
(EntityManagerInvocationHandlerFactory.java:20) at 
weblogic.persistence.PersistenceManagerObjectFactory 
.createPersistenceContextProxy(PersistenceManagerObjectFactory.java:66) at 
weblogic.persistence.PersistenceManagerObjectFactory 
.getObjectInstance(PersistenceManagerObjectFactory.java:31) at 
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304) 
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:251) at 
weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:406) at 
weblogic.j2eeclient.java.ClientReadOnlyContextWrapper.lookup 

這是觸發異常

@Stateless 
public class QuoteSessionEJB implements QuoteSessionEJBLocal { 

/** 
* Default constructor. 
*/ 
public QuoteSessionEJB() { 
    // TODO Auto-generated constructor stub 
} 

@PersistenceContext(unitName="X") 
private EntityManager em; 
/** 
* Returns a list of Quote objects in the database 
* @return List<Customer> 
*/ 
public List<Quote> getQuote() { 
Query query = em.createNamedQuery("findQuotes"); 
return query.getResultList(); 
} 

} 

這裏是位於在src /主/ JAVA persistence.xml文件中EJBBean - > META-INF其中日食建造。

<?xml version="1.0" encoding="UTF-8"?> 
<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="X" transaction-type="JTA"> 
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
    <jta-data-source>localJTA</jta-data-source> 
    <exclude-unlisted-classes>false</exclude-unlisted-classes> 
    <properties> 
     <property name="eclipselink.target-server" value="WebLogic"/> 
     <property name="eclipselink.logging.level" value="FINEST"/>   
    </properties> 
</persistence-unit> 
</persistence> 

我花了幾個小時在網上尋找答案,無濟於事。我不明白爲什麼我的persistence.xml中的持久性單元X無法找到...

我希望有人遇到了同樣的問題或知道如何解決它。 任何幫助,非常感謝!

更新: Per better_use_mkstemp下面的評論我將包含我的persistence.xml的META-INF文件夾從src/main/java移到了WEB-INF/classes。我必須在eclipse中創建類文件夾。這工作!非常感激!

正在追溯的問題:做了一些更多的研究我發現把META-INF文件夾放在src/main/resources中也可以解決問題,但是它沒有。我不知道這是否是Maven的M2E-WTP eclipse插件的問題,或者我只是在這裏誤解了一些東西。以下是該文件夾結構的屏幕截圖。

enter image description here

通過瀏覽WAR文件maven的安裝命令創建,我可以看到META-INF文件夾中正確地放置在WEB-INF/classes文件夾。但只是發佈到Eclipse內的服務器不起作用。除非我手動創建WEB-INF下的classes文件夾,並手動刪除/移動META-INF文件夾,否則我無法在IDE中使用它。另外,將兩個META-INF文件夾的副本作爲解決方案似乎沒有意義。

+2

所以,它聽起來就像你在你的耳朵/戰爭的persistence.xml驗證在WEB-INF/classes目錄/ META-INF? –

回答

0

嘗試在你的persistence.xml更換:

<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 version="1.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_1_0.xsd"> 
相關問題