jpa - Container-managed EntityManger is null on Injection -
I'm almost new to JavaEE (JRE7 / JDK1.7.0) and start my first (Maven based) Project on Eclipse (Luna) The applicant Zebos EAP 6.2.0.GA (AS 7.3.0.final- 14) which is jsf-api-2.2.7.jar and Registering JSF2.2 to updated > and module.xml by adding jsf-impl-2.2.7.jar The problem / The question is, why can not I get the injection from the Container (AS) unit in my project with the following code: * Only one stability is defined in persistence.xml so no further argument is necessary ... in my opinion !! On the other hand, when I try to get EntityManager from the container with Lookup , then EntityManager exists and everything works fine. Used for: I have read a lot of forums and tutorials - because there is a lot of discussion on this behavior - but the solution or answer can not be found. Hope someone can help me and guide me in the right direction. Thanks in advance. Edit: I use EJB 3.1 and here is persistence.xml : Thanks for the help. I tried to use EntityManager in the constructor ... which is not possible due to the initialization process. Now I have placed an initial loading (database access) in the @ PostConstruct-annotated method and it works perfectly.
@Stateless Public Square SCATRep {@ Peristons Contact Entity Manager; Private ...
@ stagnant environment (unit name = "scha", name = "firmness / m") public class SCatRep {EntityManager em; Public SCATRep (try {try} context = new initial concerts (); Em = (EntityManager) ic.lookup ("java: comp / env / persistence / em"); } Hold (naming exception e) {e.printStackTrace (); }}
& lt; Persistence xmlns = "http://java.sun.com/xml/ns/preistence" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" XSI: schema location = "http: / /java.sun.com/xml/ns/pressistence http://java.sun.com/xml/ Ns / persistence / persistence_2_0.xsd "version =" 2.0 "& gt; & Lt; Firmness unit name = "scha" transaction-type = "jta" & gt; & Lt; JTA-Data-Source & gt; Java: / scha_jndi & lt; / JTA-Data-Source & gt; & Lt; Properties & gt; & Lt ;! - SQL bid - & gt; & Lt; Property Name = "Bid" Value = "org.hibernate.dialect.MySQLDialect" /> & Lt ;! - Enable hibernate automatic session context management - & gt; & Lt; Property Name = "current_session_context_class" value = "thread" /> & Lt ;! - Standout to all executed SQL - & gt; & Lt; Property Name = "show_sql" value = "true" /> & Lt; / Properties & gt; & Lt; / Persistence unit & gt; & Lt; / Persistence>
Comments
Post a Comment