4
votes

I am trying to run my webapp on my weblogic 12c server using EJB 3.1, JPA 2.0, M2E-WTP, and JSF 2.1 technologies and continue to get the following error:

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

This is the EJBBean that is triggering the exception

@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();
}

}

Here is the persistence.xml file which is located under src/main/java --> META-INF which eclipse built.

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

I have spent hours searching the web for answers with no avail. I don't understand why the persistence unit X in my persistence.xml cannot be located...

I'm hoping someone has ran into this same problem or know hows to fix it. Any help is greatly appreciated!

Update: Per better_use_mkstemp comment below I moved the META-INF folder containing my persistence.xml from src/main/java to WEB-INF/classes. I have to create the classes folder in eclipse. This worked! Much appreciated!

Following up question: Doing some more research I found that putting the META-INF folder in src/main/resources would also solve the problem, however it did not. I dont know if this is an issue with Maven's M2E-WTP eclipse plugin or I am simply misunderstanding something here. Below is a screen shot of the folder structure.

enter image description here

By browsing the war file the maven install command creates, I can see that the META-INF folder IS correctly placed in the WEB-INF/classes folder. But simply publishing to the server within Eclipse does not work. Unless I manually create the classes folder under WEB-INF and manually drop/move the META-INF folder in there I can't get it to work inside the IDE. Also it doesn't seem to make sense to have a copy of the META-INF folder in two places as a solution.

1
So it sounds like you verified in your ear/war the persistence.xml is in WEB-INF/classes/META-INF?Display Name is missing

1 Answers

0
votes

try to replace in your 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">

for:

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