createEntityManagerFactoryProvider throws NullPointerException

Hi I'm new to JPA I made a very simple example like following:

Emp.java:

@Entity

@Table(name="EMP", schema="hr")

publicclass Emp{

@Id

privateint id;

@OneToOne(mappedBy="employINparkSpace")

private ParkSpace parkSpace;

@Column(name="NAME")

private String name;

@Basic(fetch=FetchType.LAZY)

@Column(name="SALARY")

privatelong salary;

@Column(name="DATEOFBIRTH")

private Date dateofBirth;

@ManyToOne

@JoinColumn(name="DEPTID")

private Dept department ;

}

Another class is:

@Entity

@Table(name="DEPT",schema="hr")

publicclass Dept{

public Dept(){}

public Dept(int id){ this.id = id;}

@Id

privateint id;

@Column(name="NAME")

private String name;

@OneToMany(targetEntity=Emp.class,mappedBy="department")

private Collection<Emp> emps;

}

in my EmpService I wrote:EntityManagerFactory emf =null;

EntityManager em =null;

EmpService eService =null;

try{

emf = Persistence.createEntityManagerFactory("EmpService");

em = emf.createEntityManager();

eService =new EmpService(em);

Collection<Emp> emps = eService.findAllEmps();

if (emps !=null){

for (Emp e : emps){

System.out.println("Found employee: "+e.getName()+" ,park Location:"+e.getParkSpace().getLocation());

}

}

}catch (Exception e){

e.printStackTrace();

thrownew Exception(e.getMessage());

}finally{

em.close();

emf.close();

}

This works fine but when I write same thing for Dept object as following:

EntityManagerFactory emf =null;

EntityManager em =null;

DeptService dService =null;

try{

emf = Persistence.createEntityManagerFactory("DeptService");

em = emf.createEntityManager();

dService =new DeptService(em);

Collection<Dept> deps = dService.findAllDepartments();

if ( deps!=null ){

for (Dept d: deps){

System.out.println("Department ID: "+d.getId()+" , department Name: "+d.getName());

}

}

}catch (Exception e){

e.printStackTrace();

thrownew Exception(e.getMessage());

}finally{

em.close();

emf.close();

}

I get following exceptions:

java.lang.NullPointerException

at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:120)

at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)

at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)

Can any one help me what is my problem ?

[5355 byte] By [RezaRavasizadeha] at [2007-11-27 6:20:15]
# 1
I found the problem because I did following twice:Persistence.createEntityManagerFactory(xxxx);
RezaRavasizadeha at 2007-7-12 17:35:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...