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 DAOs GetEntity methods

GetEntity methods¶

Annotate a DAO method with @GetEntity to convert a core driver data structure into one or more Entities:

@Dao
public interface ProductDao {
  @GetEntity
  Product asProduct(Row row);
}

The generated code will retrieve each entity property from the source, such as:

Product product = new Product();
product.setId(row.get("id", UUID.class));
product.setDescription(row.get("description", String.class));
...

It does not perform a query. Instead, those methods are intended for cases where you already have a query result, and just need the conversion logic.

Parameters¶

The method must have a single parameter. The following types are allowed:

  • GettableByName or one of its subtypes (the most likely candidates are Row and UdtValue).

  • ResultSet.

  • AsyncResultSet.

The data must match the target entity: the generated code will try to extract every mapped property, and fail if one is missing.

Return type¶

The method can return:

  • a single entity instance. If the argument is a result set type, the generated code will extract the first row and convert it, or return null if the result set is empty.

    @GetEntity
    Product asProduct(Row row);
    
    @GetEntity
    Product firstRowAsProduct(ResultSet resultSet);
    ```
    
  • a PagingIterable of an entity class. In that case, the type of the parameter must be ResultSet. Each row in the result set will be converted into an entity instance.

    @GetEntity
    PagingIterable<Product> asProducts(ResultSet resultSet);
    
  • a MappedAsyncPagingIterable of an entity class. In that case, the type of the parameter must be AsyncResultSet. Each row in the result set will be converted into an entity instance.

    @GetEntity
    MappedAsyncPagingIterable<Product> asProducts(AsyncResultSet resultSet);
    

If the return type doesn’t match the parameter type (for example PagingIterable for AsyncResultSet), the mapper processor will issue a compile-time error.

PREVIOUS
Delete methods
NEXT
Insert methods
  • 4.7.2.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
      • 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
      • DAOs
        • Custom result types
        • Delete methods
        • GetEntity 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

  • GetEntity methods
    • Parameters
    • Return type
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