为了提高我的应用程序的性能,我尝试使用静态编织。我用eclipelink / tomcat。
访问我的服务时出现以下错误:
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.preInitialize(ForeignReferenceMapping.java:809)
at org.eclipse.persistence.mappings.ObjectReferenceMapping.preInitialize(ObjectReferenceMapping.java:940)
at org.eclipse.persistence.descriptors.ClassDescriptor.preInitialize(ClassDescriptor.java:3320)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:429)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:230)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:369)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195)
at org.employee.resources.DeptResource.getAllDepts(DeptResource.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
我不确定我做错了什么。有人可以帮助我吗?
感谢您的帮助
修改
@Path("/employees")
public class DeptResource {
private EntityManagerFactory factory;
private EntityManager mgr;
@GET
@Produces({MediaType.APPLICATION_XML})
public List<Dept> getAllDepts(){
try
{
factory = Persistence.createEntityManagerFactory("employeeModel");
mgr = factory.createEntityManager();
}
catch (Exception e)
{
throw new Exception("..............");
}
List<Dept> deptResponseList = new ArrayList<Dept>();
try {
TypedQuery<Dept> query = mgr.createQuery("SELECT d FROM Department d", Dept.class);
Collection<Dept> deptList = query.getResultList();
Iterator<Dept> i = deptList.iterator();
while (i.hasNext())
{
Department response = new Department();
Dept dept = (Dept) i.next();
response.setDeptCode(dept.getDeptCode());
response.setDeptDesc(dept.getDeptDesc());
response.setDeptURL("URL got from another source using another web service");
deptResponseList.add(response);
}
} catch (NoResultException ex) {
mgr.close();
factory.close();
throw new Exception("------");
}
mgr.close();
factory.close();
return deptResponseList;
}