Scylla Documentation Logo Documentation
  • Server
    • Scylla Open Source
    • Scylla Enterprise
    • Scylla Alternator
  • Cloud
    • Scylla Cloud
    • Scylla Cloud Docs
  • Tools
    • Scylla Manager
    • Scylla Monitoring Stack
    • Scylla Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
Download
Menu

Caution

You're viewing documentation for a previous version of Scylla Java Driver. Switch to the latest stable version.

Scylla Java Driver Manual Mapper Integration

Integration¶

Builds tools¶

The java-driver-mapper-processor artifact contains the annotation processor. It hooks into the Java compiler, and generates additional source files from your annotated classes before the main compilation happens. It is only required in the compile classpath.

The java-driver-mapper-runtime artifact contains the annotations and a few utility classes. It is a regular dependency, required at runtime.

Maven¶

The best approach is to add the annotationProcessorPaths option to the compiler plugin’s configuration (make sure you use version 3.5 or higher):

<properties>
  <java-driver.version>...</java-driver.version>
</properties>

<dependencies>
  <dependency>
    <groupId>com.scylladb</groupId>
    <artifactId>java-driver-mapper-runtime</artifactId>
    <version>${java-driver.version}</version>
  </dependency>
</dependencies>

<build>
  <plugins>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.1</version>
      <configuration>
        <source>1.8</source> <!-- (or higher) -->
        <target>1.8</target> <!-- (or higher) -->
        <annotationProcessorPaths>
          <path>
            <groupId>com.scylladb</groupId>
            <artifactId>java-driver-mapper-processor</artifactId>
            <version>${java-driver.version}</version>
          </path>
          <!-- Optional: add this if you want to avoid the SLF4J warning "Failed to load class
            StaticLoggerBinder, defaulting to no-operation implementation" when compiling. -->
          <path>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-nop</artifactId>
            <version>1.7.26</version>
          </path>
        </annotationProcessorPaths>
      </configuration>
    </plugin>
  </plugins>
</build>

Alternatively (e.g. if you are using the BOM), you may also declare the processor as a regular dependency in the “provided” scope:

<dependencies>
  <dependency>
    <groupId>com.scylladb</groupId>
    <artifactId>java-driver-mapper-processor</artifactId>
    <version>${java-driver.version}</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>com.scylladb</groupId>
    <artifactId>java-driver-mapper-runtime</artifactId>
    <version>${java-driver.version}</version>
  </dependency>
</dependencies>

The processor runs every time you execute the mvn compile phase. It normally supports incremental builds, but if something looks off you can try a full rebuild with mvn clean compile.

One of the advantages of annotation processing is that the generated code is produced as regular source files, that you can read and debug like the rest of your application. With the above configuration, these files are in target/generated-sources/annotations. Make sure that directory is marked as a source folder in your IDE (for example, in IntelliJ IDEA, this might require right-clicking on your pom.xml and selecting “Maven > Reimport”).

Generated sources follow the same package structure as your annotated types. Most end in a special __MapperGenerated suffix, in order to clearly identify them in stack traces (one exception is the mapper builder, because it is referenced directly from your code).

Do not edit those files files directly: your changes would be overwritten during the next full rebuild.

Gradle¶

Use the following configuration (Gradle 4.6 and above):

apply plugin: 'java'

def javaDriverVersion = '...'

dependencies {
    annotationProcessor group: 'com.scylladb', name: 'java-driver-mapper-processor', version: javaDriverVersion
    compile group: 'com.scylladb', name: 'java-driver-mapper-runtime', version: javaDriverVersion
}

You will find the generated files in build/generated/sources/annotationProcessor.

Integration with other languages and libraries¶

  • Kotlin

  • Lombok

  • Java 14 records

  • Scala

PREVIOUS
Mapper
NEXT
Kotlin
  • 4.11.1.x
    • 4.13.0.x
    • 4.12.0.x
    • 4.11.1.x
    • 4.10.0.x
    • 4.7.2.x
    • 3.11.2.x
    • 3.11.0.x
    • 3.10.2.x
    • 3.7.2.x
  • Java Driver for Scylla and Apache Cassandra®
  • API Documentation
  • Manual
    • API conventions
    • Case sensitivity
    • Core driver
      • Address resolution
      • Asynchronous programming
      • Authentication
      • Bill of Materials (BOM)
      • Compression
      • Configuration
        • Reference configuration
      • Control connection
      • Custom codecs
      • Detachable types
      • Query idempotence
      • Integration
      • Load balancing
      • Logging
      • Metadata
        • Node metadata
        • Schema metadata
        • Token metadata
      • Metrics
      • Native protocol
      • Non-blocking programming
      • Paging
      • Performance
      • Connection pooling
      • Query timestamps
      • Reactive Style Programming
      • Reconnection
      • Request tracker
      • Retries
      • Using the shaded JAR
      • Speculative query execution
      • SSL
      • Statements
        • Batch statements
        • Per-query keyspace
        • Prepared statements
        • Simple statements
      • Temporal types
      • Request throttling
      • Query tracing
      • Tuples
      • User-defined types
    • Developer docs
      • Administrative tasks
      • Common infrastructure
        • Concurrency
        • Driver context
        • Event bus
      • Native protocol layer
      • Netty pipeline
      • Request execution
    • Mapper
      • Integration
        • Kotlin
        • Lombok
        • Java 14 Records
        • Scala
      • DAOs
        • Custom result types
        • Delete methods
        • GetEntity methods
        • Increment methods
        • Insert methods
        • Null saving strategy
        • Query methods
        • Query provider methods
        • Select methods
        • SetEntity methods
        • Statement attributes
        • Update methods
      • Entities
      • Mapper interface
    • OSGi
    • Query builder
      • Conditions
      • DELETE
      • Idempotence in the query builder
      • INSERT
      • Relations
      • Schema builder
        • Aggregate
        • Function
        • Index
        • Keyspace
        • Materialized View
        • Table
        • Type
      • SELECT
      • Terms
      • TRUNCATE
      • UPDATE
  • Upgrade guide
  • Frequently asked questions
  • Changelog
  • Create an issue
  • Edit this page

On this page

  • Integration
    • Builds tools
      • Maven
      • Gradle
    • Integration with other languages and libraries
Logo
Docs Contact Us About Us
Mail List Icon Slack Icon
© 2022, ScyllaDB. All rights reserved.
Last updated on 25 May 2022.
Powered by Sphinx 4.3.2 & ScyllaDB Theme 1.2.2