I am new to Java EE. This is the first project I'm trying to do, and I have a problem that I just canβt solve.
I created three projects: slowka-beans (EJB), slowka-persistance (JPA) and slowka-web (JSF). After deploying them, I cannot access the continuity unit - EntityManager is NULL. Everything works fine - I can create beans, create instances of entity classes inside them and show them on the JSF page. But how can I store them in the database? I have a MySQL database configured on a JBoss site.
The code I have is as follows: LanguagesManager.java (in slowka- beans)
@Stateless public class LanguagesManager implements LanguagesManagerLocal { @PersistenceContext(unitName="slowka-persistance") private EntityManager em; public LanguagesManager() { System.out.println("LanguagesManagerBean constructor"); } public String getWorking() { if(em == null) { System.out.println("Not working..."); return "Not working..."; } else { System.out.println("It ALIVE!"); return "It ALIVE!"; } } }
persistence.xml (slowka-persistance):
<?xml version="1.0" encoding="UTF-8"?> <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"> <persistence-unit name="slowka-persistance"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/PraktykiDS</jta-data-source> <class>pl.edu.uj.sobczak.szymon.Language</class> </persistence-unit> </persistence>
Deploying this on the server does not raise any exceptions. but I noticed the following warnings in the server output:
23:02:23,801 INFO [PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitName=slowka.ear/slowka-persistance.jar
Each time I access LanguagesManager::getWorking() from the JSP, I get the output "Doesn't work ...".
I created a project in Eclipse, JPA uses EclipseLink. I tried both - EclipseLink 1.1.4 and 2.1.0 with the same result.
Can you help me?
source share