Webapp cannot find the save group. In scope, there is no persistence unit named "X"

I am trying to run my webapp on my webcache 12c server using EJB 3.1, JPA 2.0, M2E-WTP and JSF 2.1 technologies and continue to receive 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 an EJBBean that throws an 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 is overshadowed.

 <?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 spent hours searching the Internet for answers, but to no avail. I do not understand why the persistence X element in my persistence.xml cannot be found ...

I hope someone encounters this problem or finds out how to fix it. Any help is much appreciated!

Update:. In the best_use_mkstemp comment below, I moved the META-INF folder containing my persistence.xml from src / main / java to WEB-INF / classes. I need to create a class folder in eclipse. It worked! Really appreciate!

Next question: After doing some more research, I found that installing the META-INF folder in src / main / resources would also solve the problem, but this did not happen. I do not know if this is a problem with the Maven M2E-WTP eclipse plugin, or I just don’t understand something. Below is a snapshot of the folder structure.

enter image description here

When viewing the war file created by the maven install command, I see that the META-INF folder is correctly located in the WEB-INF / classes folder. But just publishing to a server in Eclipse doesn't work. If I do not manually create the class folder in WEB-INF and manually do not drag / drop the META-INF folder there, I cannot get it to work inside the IDE. It also makes no sense to have a copy of the META-INF folder in two places as a solution.

+4
source share
1 answer

try replacing 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"> 
0
source

Source: https://habr.com/ru/post/1483600/


All Articles