agrestio / agrest

Server-side Java REST Framework for easy access to data graphs from various backends
https://agrest.io
Apache License 2.0
81 stars 34 forks source link

NPE on deleting #208

Closed IRus closed 8 years ago

IRus commented 8 years ago

LinkRest version: 2.1 Cayenne version: 4.0.M3

Hi, i run in following issue:

java.lang.NullPointerException: null
 at com.nhl.link.rest.runtime.cayenne.processor.Util.findById(Util.java:46)
 at com.nhl.link.rest.runtime.cayenne.processor.CayenneDeleteStage.deleteById(CayenneDeleteStage.java:61)
 at com.nhl.link.rest.runtime.cayenne.processor.CayenneDeleteStage.doExecute(CayenneDeleteStage.java:46)
 at com.nhl.link.rest.runtime.cayenne.processor.CayenneDeleteStage.doExecute(CayenneDeleteStage.java:24)
 at com.nhl.link.rest.processor.BaseLinearProcessingStage.execute(BaseLinearProcessingStage.java:20)
 at com.nhl.link.rest.processor.ChainProcessor.execute(ChainProcessor.java:18)
 at com.nhl.link.rest.processor.ChainProcessor.execute(ChainProcessor.java:22)
 at com.nhl.link.rest.runtime.DefaultDeleteBuilder.delete(DefaultDeleteBuilder.java:87)
 at com.objectstyle.recruiting.resource.PositionTypeResource.delete(PositionTypeResource.java:55)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
 at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
 at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
 at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
 at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
 at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
 at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
 at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
 at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:309)
 at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
 at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
 at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
 at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:292)
 at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1139)
 at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:460)
 ... 25 common frames omitted
 Wrapped by: javax.servlet.ServletException: java.lang.NullPointerException
 at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:485)
 at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)
 at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334)
 at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
 at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:821)
 at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
 at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
 at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:375)
 at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
 at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1158)
 at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
 at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
 at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1090)
 at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
 at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
 at org.eclipse.jetty.server.Server.handle(Server.java:517)
 at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
 at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
 at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
 at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
 at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
 at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
 at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
 at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
 at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
 at java.lang.Thread.run(Thread.java:745)
 WARN  [2016-10-11 12:00:46,209] bootique-http-147 o.e.j.s.HttpChannel: //localhost:3000/positions/types/tttt
 java.lang.NullPointerException: null
 at com.nhl.link.rest.runtime.cayenne.processor.Util.findById(Util.java:46)
 at com.nhl.link.rest.runtime.cayenne.processor.CayenneDeleteStage.deleteById(CayenneDeleteStage.java:61)
 at com.nhl.link.rest.runtime.cayenne.processor.CayenneDeleteStage.doExecute(CayenneDeleteStage.java:46)
 at com.nhl.link.rest.runtime.cayenne.processor.CayenneDeleteStage.doExecute(CayenneDeleteStage.java:24)
 at com.nhl.link.rest.processor.BaseLinearProcessingStage.execute(BaseLinearProcessingStage.java:20)
 at com.nhl.link.rest.processor.ChainProcessor.execute(ChainProcessor.java:18)
 at com.nhl.link.rest.processor.ChainProcessor.execute(ChainProcessor.java:22)
 at com.nhl.link.rest.runtime.DefaultDeleteBuilder.delete(DefaultDeleteBuilder.java:87)
 at com.objectstyle.recruiting.resource.PositionTypeResource.delete(PositionTypeResource.java:55)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
 at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
 at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
 at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
 at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
 at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
 at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
 at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
 at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:309)
 at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
 at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
 at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
 at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:292)
 at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1139)
 at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:460)
 ... 25 common frames omitted
 Wrapped by: javax.servlet.ServletException: java.lang.NullPointerException
 at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:485)
 at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)
 at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334)
 at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
 at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:821)
 at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
 at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
 at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:375)
 at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
 at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1158)
 at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
 at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
 at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1090)
 at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
 at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
 at org.eclipse.jetty.server.Server.handle(Server.java:517)
 at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
 at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
 at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
 at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
 at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
 at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
 at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
 at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
 at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
 at java.lang.Thread.run(Thread.java:745)

Entity:

public abstract class _PositionType extends CayenneDataObject {

    private static final long serialVersionUID = 1L; 

    public static final String TYPE_PK_COLUMN = "TYPE";

    public static final Property<String> TYPE = new Property<String>("type");
    public static final Property<List<Position>> TO_POSITION = new Property<List<Position>>("toPosition");

    public void setType(String type) {
        writeProperty("type", type);
    }
    public String getType() {
        return (String)readProperty("type");
    }

    public void addToToPosition(Position obj) {
        addToManyTarget("toPosition", obj, true);
    }
    public void removeFromToPosition(Position obj) {
        removeToManyTarget("toPosition", obj, true);
    }
    @SuppressWarnings("unchecked")
    public List<Position> getToPosition() {
        return (List<Position>)readProperty("toPosition");
    }

}

Controller:

@Path("/positions/types")
@Produces(MediaType.APPLICATION_JSON)
public class PositionTypeResource {

    private final Configuration config;

    public PositionTypeResource(@Context Configuration config) {
        this.config = config;
    }

    @DELETE
    @Path("{id}")
    public SimpleResponse delete(@PathParam("id") String id) {
        return LinkRest.delete(PositionType.class, config).id(id).delete();
    }
}
// com/nhl/link/rest/runtime/cayenne/processor/Util.java:46
entity.getDbEntity().getAttribute(idName) // returns null, idName="type" 

Looks like getAttribute expecting "TYPE" instead of "type".

atomashpolskiy commented 8 years ago

Hi @IRus , so in the database you have PK named TYPE and a separate column named type, is that correct?

IRus commented 8 years ago

Hi, no, in the database i have one column named TYPE which is PK:

CREATE TABLE `position_type` (
  `TYPE` VARCHAR(100) NOT NULL,
  PRIMARY KEY (`TYPE`)
);
atomashpolskiy commented 8 years ago

I see, then there's an object attribute named type that maps to PK, right? I've commited a fix.

IRus commented 8 years ago

Right, thank you.