devng / twig-persist

Automatically exported from code.google.com/p/twig-persist
0 stars 0 forks source link

can't embed a Map in 2.0 branch #35

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Persist an object with @Embedded (previously @Embed) annotation on a 
Map<String,String>.

What is the expected output? What do you see instead?

Since one can embed a List, I was hoping that one could also embed a Map. You 
get the following stacktrace with v2.0-alpha release, but I also had the same 
problem with latest v2.0 branch code:

Caused by: java.lang.IllegalStateException: Final field private final int 
java.lang.String.count cannot be stored
    at com.google.code.twig.annotation.AnnotationStrategy.store(AnnotationStrategy.java:67)
    at com.google.code.twig.standard.StrategyObjectDatastore$StrategyObjectFieldTranslator.stored(StrategyObjectDatastore.java:554)
    at com.google.code.twig.translator.ObjectFieldTranslator.encode(ObjectFieldTranslator.java:298)
    at com.google.code.twig.translator.MapTranslator.encode(MapTranslator.java:86)
    at com.google.code.twig.translator.ListTranslator.encode(ListTranslator.java:242)
    at com.google.code.twig.translator.ObjectFieldTranslator.encode(ObjectFieldTranslator.java:321)
    at com.google.code.twig.standard.StandardCommonStoreCommand.instanceToEntity(StandardCommonStoreCommand.java:213)
    at com.google.code.twig.standard.StandardSingleStoreCommand.now(StandardSingleStoreCommand.java:51)
    at com.google.code.twig.standard.StrategyObjectDatastore.store(StrategyObjectDatastore.java:159)
    at com.google.code.twig.standard.StrategyObjectDatastore.storeOrUpdate(StrategyObjectDatastore.java:249)
  ...

What version of the product are you using? On what operating system?

2.0 branch

Original issue reported on code.google.com by haag...@comcast.net on 7 Sep 2010 at 3:35

GoogleCodeExporter commented 8 years ago
The 'count' field in the stacktrace is one of the internal String object's 
fields. I'm just guessing that something needs to be done to only store the 
string-text itself, instead of using reflection to persist all the internal 
fields of String.

Original comment by haag...@comcast.net on 7 Sep 2010 at 3:38

GoogleCodeExporter commented 8 years ago
Because String is a "native" type you do not need to declare the Map @Embedded. 
 The MapTranslator is a part of the standard translators in v2.0 and does not 
need any extra configuration to work.

Twig is trying to embed the String objects which means analysing its fields to 
store as properties.

Original comment by jdpatterson on 7 Sep 2010 at 9:03

GoogleCodeExporter commented 8 years ago
That's ok, thanks for the explanation. Would it make sense to detect this kind 
of misconfiguration and notify the developer of the problem?

Original comment by haag...@comcast.net on 7 Sep 2010 at 3:00

GoogleCodeExporter commented 8 years ago
Good point.  I've added some extra context to the exception:

            if (DataTypeUtils.isSupportedType(object.getClass()))
            {
                throw new IllegalStateException("Native data type " + object.getClass() + " should not be configured as embedded");
            }

Original comment by jdpatterson on 7 Sep 2010 at 3:19