621 words

Null returned by Persistence.createEntityManagerFactory

#1
2014-06-12 18:11

Hi,

So I'm currently having an issue where createEntityManagerFactory returns null. When I run the application on the my local machine through Tomcat it works fine, the odb file is created. 

 

public class TaskDaoODBImpl implements TaskDao {
    private EntityManagerFactory emf;
 
   private EntityManager em;
 
   public TaskDaoODBImpl(){
            emf =  Persistence.createEntityManagerFactory("C:/objectdb-2.5.5_12/db/tasks.odb");
            em = emf.createEntityManager();
            em.find(Task.class, Task.class);
 
 
    }

Here's my object (I removed the getters and setters): 

@Entity
public class Task implements Serializable {
@Id @GeneratedValue int id;
//int id = 0;
private String ticketNumber;
private String createdDate;
private String updatedDate;
private String dueDate;
private String description;
private String owner;
private String status;
private String approvalGroup;
private String details;
private String notes = "";
private String ppmc = "";
private String cmTicket = "";
private int leadTimeDays = 0;
private String type = "System-Generated";
 
  public Task(String ticketNumber, String owner, String approvalGroup, String description, String details){
 
  this.ticketNumber = ticketNumber;
  this.approvalGroup = approvalGroup;
  this.description = description;
  this.status = "Not Started";
  this.owner = owner;
  this.details = details;
}
public Task(String ticketNumber, String createdDate, String approvalGroup,
   String description, String owner, String dueDate, String status) {
  super();
  this.ticketNumber = ticketNumber;
  this.createdDate = createdDate;
  this.dueDate = dueDate;
  this.description = description;
  this.owner = owner;
  this.status = status;
  this.approvalGroup = approvalGroup;
}
 
 
public int getId(){
  return id;
}
 
}

 

The problem comes up when I attempt to run this on an IBM Websphere server.  I modify the path on the createEntityManagerFactory call:

 

public class TaskDaoODBImpl implements TaskDao {
    private EntityManagerFactory emf;
 
   private EntityManager em;
 
   public TaskDaoODBImpl(){
            emf =  Persistence.createEntityManagerFactory("/lsppordev1/app/lsppo/db/tasks.odb");
            em = emf.createEntityManager();
            em.find(Task.class, Task.class);
 
 
    }

The application is deployed to Websphere as an EAR file. When I attempt to access the application I get an exception. The exception is ultimately caused by a null pointer on the line "em = emf.createEntityManager()" in TaskDaoOBDImpl. I've attached a copy of the exception below. 

I'm not using a persistence.xml file in this case to define the location of the database since I have two different databases to connect to.

Any ideas what could be causing this?

Thanks,

elks

 

elks
elks's picture
Joined on 2014-06-12
User Post #1
#2
2014-06-12 18:47

As you can see in the following code of Persistence (which is a JPA class rather than an ObjectDB class), it may throw an exception but it never returns null:

    public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName) {
        return createEntityManagerFactory(persistenceUnitName, null);
    }
 
    public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
 
        EntityManagerFactory emf = null;
        PersistenceProviderResolver resolver = PersistenceProviderResolverHolder.getPersistenceProviderResolver();
 
        List<PersistenceProvider> providers = resolver.getPersistenceProviders();
 
        for (PersistenceProvider provider : providers) {
            emf = provider.createEntityManagerFactory(persistenceUnitName, properties);
            if (emf != null) {
                break;
            }
        }
        if (emf == null) {
            throw new PersistenceException("No Persistence provider for EntityManager named " + persistenceUnitName);
        }
        return emf;
    }
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,958
#3
2014-06-12 19:17

Hi,

Okay, that makes sense.

Are there other reasons why the null pointer may be happening? I haven't seen that persistence exception.

I'm trying to figure out if there is some kind of configuration issue.

Thanks,

elks

elks
elks's picture
Joined on 2014-06-12
User Post #2
#4
2014-06-12 20:04

No idea. Seems unrelated to ObjectDB.

But maybe you should verify first that the exception is thrown where you think it is, because stack traces are occasionally inaccurate. Try to change your code by moving suspected lines to separate methods, etc.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,959

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel