I also posted this in the play framework group but maybe somebody here has
also come across this while using elasticsearch with the Play framework.
I ran into this issue when using the elasticsearch plugin for the Play
framework. The elasticsearch index contains a string value for the enum *ClassName.type
*
and the field mapper for the elasticsearch plugin cannot create a new enum
type with the string returned from the index. I also embedded the enum but
the enum could not be instantiated (see error below). It's a very specific
area of Play but has anyone come across this before or know if enum types
can be embedded or even a workaround to allow the mapper to map a string to
an enum type.
Error when trying to map a string as an enum value
ERROR ~
java.lang.IllegalArgumentException: Can not set models.ClassName$EnumName
field models.ClassName.type to java.lang.String
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown
Source)
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown
Source)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)
at java.lang.reflect.Field.set(Unknown Source)
at
play.modules.elasticsearch.util.ReflectionUtil.setFieldValue(ReflectionUtil.java:419)
at
play.modules.elasticsearch.util.ReflectionUtil.setFieldValue(ReflectionUtil.java:397)
at
play.modules.elasticsearch.mapping.impl.SimpleFieldMapper.inflate(SimpleFieldMapper.java:50)
at
play.modules.elasticsearch.mapping.impl.EmbeddedFieldMapper.inflate(EmbeddedFieldMapper.java:161)
at
play.modules.elasticsearch.mapping.impl.PlayModelMapper.createModel(PlayModelMapper.java:156)
at
play.modules.elasticsearch.mapping.impl.PlayModelMapper.createModel(PlayModelMapper.java:29)
at
play.modules.elasticsearch.transformer.MapperTransformer.toSearchResults(MapperTransformer.java:75)
at play.modules.elasticsearch.Query.fetch(Query.java:188)
at controllers.Search$ObjectType.findPagewitFilter(Search.java:1545)
at controllers.Search.getCountForFilterMenuItem(Search.java:449)
at controllers.Search.search(Search.java:229)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:257)
at play.Invoker$Invocation.run(Invoker.java:278)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:235)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown
Source)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown
Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Error when embedding an enum and trying to retrieve the value as an enum
type.
@6b6jpgfp4
Internal Server Error (500) for request GET /productsearch/search
Execution exception (In /app/controllers/Search.java around line 1545)
RuntimeException occured : Cannot instantiate class
models.CoreAsset$AssetType
play.exceptions.JavaExecutionException: Cannot instantiate class
models.CoreAsset$AssetType
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException: Cannot instantiate class
models.CoreAsset$AssetType
at
play.modules.elasticsearch.util.ReflectionUtil.newInstance(ReflectionUtil.java:270)
at
play.modules.elasticsearch.mapping.impl.EmbeddedFieldMapper.inflate(EmbeddedFieldMapper.java:153)
at
play.modules.elasticsearch.mapping.impl.EmbeddedFieldMapper.inflate(EmbeddedFieldMapper.java:161)
at
play.modules.elasticsearch.mapping.impl.PlayModelMapper.createModel(PlayModelMapper.java:156)
at
play.modules.elasticsearch.mapping.impl.PlayModelMapper.createModel(PlayModelMapper.java:29)
at
play.modules.elasticsearch.transformer.MapperTransformer.toSearchResults(MapperTransformer.java:75)
at play.modules.elasticsearch.Query.fetch(Query.java:188)
at controllers.Search$ObjectType.findPagewitFilter(Search.java:1545)
at controllers.Search.getCountForFilterMenuItem(Search.java:410)
at controllers.Search.search(Search.java:216)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
... 1 more
Caused by: java.lang.IllegalArgumentException: Cannot reflectively create
enum objects
at
play.modules.elasticsearch.util.ReflectionUtil.newInstance(ReflectionUtil.java:268)