Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntityManagerFactory is null #43

Open
joymallyac opened this issue Jul 8, 2020 · 0 comments
Open

EntityManagerFactory is null #43

joymallyac opened this issue Jul 8, 2020 · 0 comments

Comments

@joymallyac
Copy link

joymallyac commented Jul 8, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant