Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

uppal.samar_175105 avatar image
uppal.samar_175105 asked ·

cassandra java driver annotation processing

Hello, I am using the Java driver 4.1.0. Also, am using the java-driver-mapper-processor & java-driver-mapper-runtime dependencies to use the object mapping functionality.

However, when I annotate with @mapper, this page says https://docs.datastax.com/en/developer/java-driver/4.1/manual/mapper/ that i need to do annotation processing to generate the mapper object.

In intellij i checked the use annotation processing and set the path to the processor jar. However, the annotations are not processed

How do I get access to the InventoryMapperBuilder object and hence the InventoryMapper object if the annotations are not processed.

Am stuck here, will really appreciate any help

btw, am using sbt with play

so no maven, gradle etc

driverjava
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

olivier.michallat_30685 avatar image
olivier.michallat_30685 answered ·

I'm not familiar with SBT, but from what I can find online it doesn't have native support for Java annotation processors. You'll need to write a custom task to invoke javac with the processor options; this StackOverflow question looks like a good starting point.

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

uppal.samar_175105 avatar image
uppal.samar_175105 answered ·

Thanks Olivier, that got me going. Essentially, in the javac options I am using -processorPath and specifying the full path to my processor jar:

/Users/samarjit.uppal/.ivy2/cache/com.datastax.oss/java-driver-mapper-processor/jars/java-driver-mapper-processor-4.1.0.jar


The javac command is essentially the following; am only doing the annotation processing (no compiling):

javac -classpath ... -proc:only -processorpath /Users/samarjit.uppal/.ivy2/cache/com.datastax.oss/java-driver-mapper-processor/jars/java-driver-mapper-processor-4.1.0.jar  -XprintRounds -s /Users/samarjit.uppal/projects/paymentinterfaceservice/target/generated_sources repository.impl.IPaymentMapper repository.impl.IPaymentRequestDao

I can also see that my classpath has the mapper-runtime jar:

/Users/samarjit.uppal/.ivy2/cache/com.datastax.oss/java-driver-mapper-runtime/bundles/java-driver-mapper-runtime-4.1.0.jar

However, when the processor begins to do its work, it cant seem to find the defined annotations in the runtime jar.

Here is the exception:

An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.NoClassDefFoundError: com/datastax/oss/driver/api/mapper/annotations/Entity
    at com.datastax.oss.driver.internal.mapper.processor.MapperProcessor.getSupportedAnnotationTypes(MapperProcessor.java:133)

Why is the mapper unable to locate the annotation package when its in the classpath?



Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.