Home » Support » Forum » Null returned by Persistence.createEntityManagerFactory

Null returned by Persistence.createEntityManagerFactory

#1

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

 

#2

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)
#3

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

#4

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)

Post Reply

To post a reply and/or subscribe to update notifications - please login