hy
我在java网络复制场使用实体经理时遇到麻烦。
我的法典是:
public class HelloWorldResource extends ServerResource {
@PersistenceContext(unitName = "TestRestletPU")
EntityManagerFactory emf;
@Get
public String represent() {
EntityManager em = emf.createEntityManager();
if(em.isOpen())
return "good";
else
return "bad";
}
页: 1
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns /persistence/persistence_2_0.xsd">
<persistence-unit name="TestRestletPU" transaction-type="JTA">
<jta-data-source>Test</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
我的所有实体类别和持久性。 xml是自动生成的,因此,我认为有点错误。
我每次都会发现这一错误:
java.lang.NullPointerException
at firstSteps.HelloWorldResource.represent(HelloWorldResource.java:23)
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)
at org.restlet.resource.ServerResource.doHandle(ServerResource.java:449)
at org.restlet.resource.ServerResource.get(ServerResource.java:645)
at org.restlet.resource.ServerResource.doHandle(ServerResource.java:527)
at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:587)
at org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:299)
at org.restlet.resource.ServerResource.handle(ServerResource.java:846)
at org.restlet.resource.Finder.handle(Finder.java:510)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:203)
at org.restlet.routing.Router.doHandle(Router.java:497)
at org.restlet.routing.Router.handle(Router.java:737)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:203)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:203)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:151)
at org.restlet.routing.Filter.handle(Filter.java:203)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:203)
at org.restlet.engine.ChainHelper.handle(ChainHelper.java:111)
at org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.java:72)
at org.restlet.Application.handle(Application.java:388)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:203)
at org.restlet.routing.Router.doHandle(Router.java:497)
at org.restlet.routing.Router.handle(Router.java:737)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:203)
at org.restlet.routing.Router.doHandle(Router.java:497)
at org.restlet.routing.Router.handle(Router.java:737)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:151)
at org.restlet.routing.Filter.handle(Filter.java:203)
at org.restlet.routing.Filter.doHandle(Filter.java:156)
at org.restlet.routing.Filter.handle(Filter.java:203)
at org.restlet.engine.ChainHelper.handle(ChainHelper.java:111)
at org.restlet.Component.handle(Component.java:388)
at org.restlet.Server.handle(Server.java:488)
at org.restlet.engine.http.connector.BaseServerHelper.handle(BaseServerHelper.java:158)
at org.restlet.engine.http.connector.BaseServerHelper.handleInbound(BaseServerHelper.java:167)
at org.restlet.engine.http.connector.BaseHelper.handleNextInbound(BaseHelper.java:418)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:695)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Can anyone help me out.