Issue 14337

Creating new datasets with invalid installation keys throws 500

14337
Reporter: mdoering
Type: Bug
Summary: Creating new datasets with invalid installation keys throws 500
Priority: Major
Status: Open
Created: 2013-11-07 13:22:36.404
Updated: 2013-12-12 17:32:44.466
        
Description: When POSTing new datasets with a valid organisationKey, but a non existing installation key no validation/bad request error is returned, but instead a postgres sql error bubbles up and results in an http 500 server error.

----------
iggy:Desktop mdoering$ curl -i --user markus:markus -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d @ds.json http://localhost:8080/dataset
HTTP/1.1 500  ### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: insert or update on table "dataset" violates foreign key constraint "dataset_installation_key_fkey"   Detail: Key (installation_key)=(173f7139-f7df-4fdf-a76f-0b0cdee9471e) is not present in table "installation". ### The error may involve org.gbif.registry.persistence.mapper.DatasetMapper.create-Inline ### The error occurred while setting parameters ### SQL: INSERT INTO dataset(      key,parent_dataset_key,duplicate_of_dataset_key,installation_key,owning_organization_key,     external,type,sub_type,title,alias,abbreviation,description,language,     homepage,logo_url,citation,citation_identifier,rights,locked_for_auto_update,created,created_by,     modified,modified_by    )     VALUES(      ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     now(),          ?,     now(),          ?    ) ### Cause: org.postgresql.util.PSQLException: ERROR: insert or upda
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 19767
Server: Jetty(8.1.9.v20130131)




Error 500
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: insert or update on table "dataset" violates foreign key constraint "dataset_installation_key_fkey"
  Detail: Key (installation_key)=(173f7139-f7df-4fdf-a76f-0b0cdee9471e) is not present in table "installation".
### The error may involve org.gbif.registry.persistence.mapper.DatasetMapper.create-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO dataset(      key,parent_dataset_key,duplicate_of_dataset_key,installation_key,owning_organization_key,     external,type,sub_type,title,alias,abbreviation,description,language,     homepage,logo_url,citation,citation_identifier,rights,locked_for_auto_update,created,created_by,     modified,modified_by    )     VALUES(      ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     now(),          ?,     now(),          ?    )
### Cause: org.postgresql.util.PSQLException: ERROR: insert or update on table "dataset" violates foreign key constraint "dataset_installation_key_fkey"
  Detail: Key (installation_key)=(173f7139-f7df-4fdf-a76f-0b0cdee9471e) is not present in table "installation".

HTTP ERROR 500

Problem accessing /dataset. Reason:

### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: insert or update on table "dataset" violates foreign key constraint "dataset_installation_key_fkey"
  Detail: Key (installation_key)=(173f7139-f7df-4fdf-a76f-0b0cdee9471e) is not present in table "installation".
### The error may involve org.gbif.registry.persistence.mapper.DatasetMapper.create-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO dataset(      key,parent_dataset_key,duplicate_of_dataset_key,installation_key,owning_organization_key,     external,type,sub_type,title,alias,abbreviation,description,language,     homepage,logo_url,citation,citation_identifier,rights,locked_for_auto_update,created,created_by,     modified,modified_by    )     VALUES(      ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     now(),          ?,     now(),          ?    )
### Cause: org.postgresql.util.PSQLException: ERROR: insert or update on table "dataset" violates foreign key constraint "dataset_installation_key_fkey"
  Detail: Key (installation_key)=(173f7139-f7df-4fdf-a76f-0b0cdee9471e) is not present in table "installation".

Caused by:

org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: insert or update on table "dataset" violates foreign key constraint "dataset_installation_key_fkey"
  Detail: Key (installation_key)=(173f7139-f7df-4fdf-a76f-0b0cdee9471e) is not present in table "installation".
### The error may involve org.gbif.registry.persistence.mapper.DatasetMapper.create-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO dataset(      key,parent_dataset_key,duplicate_of_dataset_key,installation_key,owning_organization_key,     external,type,sub_type,title,alias,abbreviation,description,language,     homepage,logo_url,citation,citation_identifier,rights,locked_for_auto_update,created,created_by,     modified,modified_by    )     VALUES(      ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     now(),          ?,     now(),          ?    )
### Cause: org.postgresql.util.PSQLException: ERROR: insert or update on table "dataset" violates foreign key constraint "dataset_installation_key_fkey"
  Detail: Key (installation_key)=(173f7139-f7df-4fdf-a76f-0b0cdee9471e) is not present in table "installation".
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:150)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:137)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.apache.ibatis.session.SqlSessionManager$SqlSessionInterceptor.invoke(SqlSessionManager.java:282)
	at $Proxy56.insert(Unknown Source)
	at org.apache.ibatis.session.SqlSessionManager.insert(SqlSessionManager.java:195)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:46)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
	at $Proxy57.create(Unknown Source)
	at org.gbif.registry.persistence.WithMyBatis.create(WithMyBatis.java:46)
	at org.gbif.registry.ws.resources.BaseNetworkEntityResource.create(BaseNetworkEntityResource.java:169)
	at org.apache.bval.guice.ValidateMethodInterceptor.invoke(ValidateMethodInterceptor.java:92)
	at org.gbif.registry.ws.resources.BaseNetworkEntityResource.create(BaseNetworkEntityResource.java:155)
	at org.gbif.registry.ws.guice.StringTrimInterceptor.invoke(StringTrimInterceptor.java:75)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
	at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
	at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
	at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
	at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
	at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
	at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
	at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263)
	at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178)
	at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
	at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62)
	at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
	at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
	at org.gbif.registry.ws.filter.StaticContentFilter.doFilter(StaticContentFilter.java:52)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:368)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:488)
	at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:943)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1004)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:861)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:722)
Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "dataset" violates foreign key constraint "dataset_installation_key_fkey"
  Detail: Key (installation_key)=(173f7139-f7df-4fdf-a76f-0b0cdee9471e) is not present in table "installation".
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:410)
	at com.jolbox.bonecp.PreparedStatementHandle.execute(PreparedStatementHandle.java:138)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:100)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:148)
	... 68 more

Caused by:

org.postgresql.util.PSQLException: ERROR: insert or update on table "dataset" violates foreign key constraint "dataset_installation_key_fkey"
  Detail: Key (installation_key)=(173f7139-f7df-4fdf-a76f-0b0cdee9471e) is not present in table "installation".
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
]]>