Reputation: 334
I have some service to persist object to context and face a null EntityManager
when run it
@Stateless
public class PointServies {
@PersistenceContext(name="pointProvider",type = PersistenceContextType.EXTENDED)
private EntityManager em;
public void addMovie(Point point) throws Exception {
em.persist(point); // em is null here.
}
}
this is my persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="pointProvider">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>model.Point</class>
<properties>
<!-- Configuring JDBC properties -->
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/testdb" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="admin" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<!-- Hibernate properties -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
</properties>
</persistence-unit>
looks like PersistenceContext
can't find my xml.....
The persistence.xml
exist in "src/META-INF/persistence.xml"
and all the other sources reside in "src/model/Point"
I try to run this project on Tomcat 8 web-container.
Upvotes: 2
Views: 1194
Reputation: 462
Tomcat doesn't support EJB by default, i reccommand you either add the OpenEJB webapp to Tomcat, or use full-stack application server like GlassFish or WebLogic Server.
Upvotes: 2