0

I'm using EclipseLink as the JPA provider but on calling:

Persistence.createEntityManagerFactory("emfactory1")

I get this exception:

java.lang.ClassNotFoundException: javax.persistence.Persistence

The pom.xml file reads as follows:

<dependency>
  <groupId>org.eclipse.persistence</groupId>
  <artifactId>eclipselink</artifactId>
  <version>2.6.4</version>
</dependency>

On looking around I found a suggestion to fetch only the JPA API:

<artifactId>javax.persistence</artifactId>

But that still gives me the same exception. Suffice to say I'm now stranded and in need of assistance.

Edit

Here's a screenshot of the output output

Eliud Daniels
  • 63
  • 1
  • 8

1 Answers1

0

Reason of Error: Data source is missing in your code.

Try this.

InitialContext ctx = new InitialContext();
                        DataSource ds = (DataSource) ctx.lookup(DATA_SOURCE_NAME);

                        Map<String, Object> properties = new HashMap<>();
                        properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, ds);
                        entityManagerFactory = Persistence.createEntityManagerFactory(
                                PERSISTENCE_UNIT_NAME, properties);
Atul Jain
  • 1,035
  • 2
  • 16
  • 24