cassandra-driver-mapping 3.1.0 MappingManager#mapper fails for Groovy class

102 views
Skip to first unread message

Jason Januzelli

unread,
Sep 2, 2016, 1:55:08 PM9/2/16
to DataStax Java Driver for Apache Cassandra User Mailing List
We implement our @Table mappings as Groovy classes.  This has worked fine with previous releases of the MappingManager thru release 3.0.3.  With the latest 3.1.0 release, it appears MappingManager requires there to be a column defined for the Groovy MetaClass property.  Comparing the source between 3.0.3 and 3.1.0, it looks like reflective inspection of the entity class has changed considerably within com.datastax.driver.mapping.AnnotationParser#parseEntity.  The new 3.1.0 source utilizes com.datastax.driver.mapping.ReflectionUtils.scanFieldsAndProperties which picks up the MetaClass property.  Creation of the Mapper fails since the actual table metadata does not include a corresponding column for the Groovy class's MetaClass.

Any suggestions?  Obviously we can convert all our mappings to Java classes but that's not desirable.

Andrew Tolbert

unread,
Sep 5, 2016, 10:19:55 AM9/5/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Jason,

Could you share the exception stack trace and an example of a Groovy class that fails to map?  That may help us understand what we need to fix.

Thanks,
Andy

Alexandre Dutra

unread,
Sep 5, 2016, 10:37:15 AM9/5/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Jason,

This is due to JAVA-636, that added support for mapped properties through both fields and getters, and also to the fact the the mapper has an opt-out approach when scanning for such properties, i.e, you need to explicitly exclude a property from being mapped by using the @Transient annotation.

Of course, this is a problem for auto-generated properties, like Groovy's "metaClass" property. I created JAVA-1279 to track this issue. In the meanwhile, I experimented with the following workaround: in each of your mapped classes, override the "metaClass" property and annotate it with @Transient:
@Transient
def MetaClass metaClass = super.metaClass;
It makes things work as far as the mapper is concerned, although I wouldn't guarantee that id does not introduce side-effects as I'm no Groovy expert.

Hope that helps!

Cheers,

Alexandre



--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
--
Alexandre Dutra
Driver & Tools Engineer @ DataStax

Jason Januzelli

unread,
Sep 6, 2016, 8:29:35 AM9/6/16
to DataStax Java Driver for Apache Cassandra User Mailing List
We'll hold off on upgrading to the 3.1 driver for a bit and watch for any movement on JAVA-1279.  If we get to the point of needing to upgrade before JAVA-1279 is resolved, we'll evaluate whether to go with the proposed workaround or to refactor our mappings to Java classes.

Thanks.
Reply all
Reply to author
Forward
0 new messages