Skip to content

EntityManagerFactory is null  #43

Description

@joymallyac

I have been following the steps shown in articles-java-jee to create EntityManagerFactory. I have made the necessary changes in persistence.xml,server.xmland also put beans.xml inside WEB-INFfolder. In spite of that when I create EntityManagerFactory, it becomes null.

@PersistenceContext(name = "jpa-unit") static EntityManagerFactory emf;	
static EntityManager em = emf.createEntityManager();

Persistence.xml

<persistence version="2.2"
    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_2.xsd">
    <persistence-unit name="jpa-unit" transaction-type="JTA">
        <jta-data-source>jdbc/articlejpadatasource</jta-data-source>       
        <properties>
            <property name="eclipselink.ddl-generation" value="create-tables"/>
            <property name="eclipselink.ddl-generation.output-mode" value="both" />
        </properties>
    </persistence-unit>
</persistence>




Server.xml

<library id="DB2JCCLib">
        <fileset dir="${shared.resource.dir}/db2jars" includes="jcc*.jar"/>
    </library>

    <dataSource id="articlejpadatasource"
              jndiName="jdbc/articlejpadatasource">
        <jdbcDriver libraryRef="DB2JCCLib" />
        <properties.db2.jcc databaseName=""
            portNumber="50000"
            serverName=""         
            user="" 
            password="" />
  </dataSource>

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
    bean-discovery-mode="all">
</beans>

pom.xml

<dependency>
   	   <groupId>com.ibm.db2</groupId>
   	   <artifactId>jcc</artifactId>
   	   <version>11.1.4.4</version>
	</dependency>

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-dependency-plugin</artifactId>
	<version>2.10</version>
	<executions>
			<execution>
					<id>copy-jcc-dependency</id>
					<phase>package</phase>
					<goals>
							<goal>copy-dependencies</goal>
					</goals>
					<configuration>
							<includeArtifactIds>jcc</includeArtifactIds>
							<outputDirectory>${project.build.directory}/</outputDirectory>
					</configuration>
			</execution>
	</executions>
	</plugin>

What am I missing?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions