Skip to main content

Overview

This guide covers the essential changes needed to migrate your Ditto Java app from v4 to v5. The main architectural shift is moving from identity-based initialization to a three-phase configuration model with CompletableFuture-based APIs. Also required: v5 uses DQL (Ditto Query Language) for all data operations. See the DQL Migration Guide for query migration steps.

AI Agent Prompt

Use this prompt when working with an AI coding assistant to migrate your Ditto Java app from v4 to v5.

Ditto Instance Initialization

v5 separates initialization into three distinct phases for better clarity and control:
These changes provide:
  • Clear separation of connection, initialization, and authentication concerns
  • CompletableFuture-based async authentication
  • No workarounds needed (transport config, DQL strict mode, v3 sync disable)
  • Type-safe configuration with compile-time validation
Initialization Migration Steps
1

Replace Initialization

Replace new Ditto() constructor with DittoFactory.create(config).
Key changes:
  • Use DittoConfig.Builder pattern instead of DittoIdentity
  • appId β†’ databaseId
  • .OnlinePlayground β†’ new DittoConfig.Connect.Server(...)
  • .OfflinePlayground β†’ new DittoConfig.Connect.SmallPeersOnly(null)
  • Remove updateTransportConfig, disableSyncWithV3(), and DQL strict mode queries
2

Update Authentication

Set authentication handler separately after initialization.
Key changes:
  • Authentication now uses setExpirationHandler callback
  • Handler called when auth required (timeUntilExpiration == 0) or token expiring
  • Use DittoAuthenticationProvider.development() for playground tokens
  • Custom auth: new DittoAuthenticationProvider("your-provider")

Additional Changes

DQL Strict Mode Behavior Change

Breaking Change: v5 defaults to DQL_STRICT_MODE=false, which fundamentally changes how DQL queries behave.
  • v4 default: Objects treated as REGISTER (whole-object replacement)
  • v5 default: Objects treated as MAP (field-level merging)
This affects the behavior of all DQL SELECT, INSERT, and UPDATE operations.
Choose the appropriate migration path based on your current v4 configuration:
If you’re currently using the v4 default (DQL_STRICT_MODE=true), you must explicitly set strict mode to true in v5 before starting sync or executing any queries.
Failing to set strict mode will cause objects to merge at the field level instead of replacing entirely, which can result in unexpected data behavior and perceived data loss.
To migrate to DQL_STRICT_MODE=false (the new v5 default), contact Ditto Customer Support for guidance.
If you explicitly set DQL_STRICT_MODE=false in v4, no changes are required.v5 uses DQL_STRICT_MODE=false as the default, so your existing DQL queries will behave identically. You can upgrade freely.Optional: You can remove the explicit ALTER SYSTEM SET DQL_STRICT_MODE = false statement in v5 since this is now the default behavior.
The Legacy Query Builder has been removed in v5. All queries must be converted to DQL before upgrading.Good news: Legacy Query Builder functionality has 1:1 support with DQL_STRICT_MODE=false (the v5 default), making migrations straightforward.Migration Steps:
  1. In v4: Set DQL_STRICT_MODE=false after initialization:
  2. Convert all queries from Legacy Query Builder to DQL See the Java Legacy→DQL Migration Guide for detailed conversion examples.
  3. Upgrade to v5 No DQL configuration changes requiredβ€”v5 defaults to DQL_STRICT_MODE=false.

Default Persistence Directory

v5 includes the database ID in the default directory name: ditto-{databaseId} instead of ditto To maintain v4 compatibility:

API Changes

  • ditto.startSync() β†’ ditto.getSync().start()
  • ditto.stopSync() β†’ ditto.getSync().stop()
  • ditto.isSyncActive() β†’ ditto.getSync().isActive()
  • getPeerKeyString() β†’ getPeerKey()
  • isConnectedToDittoCloud() β†’ isConnectedToDittoServer()
  • new Ditto() β†’ DittoFactory.create(config)

Migration Checklist

Initialization

  • Replace new Ditto() with DittoFactory.create(config)
  • Create DittoConfig with databaseId and connect mode
  • Update .OnlinePlayground β†’ new DittoConfig.Connect.Server(...)
  • Update .OfflinePlayground β†’ new DittoConfig.Connect.SmallPeersOnly(null)
  • Remove updateTransportConfig calls
  • Remove disableSyncWithV3() calls
  • Set DQL_STRICT_MODE=true BEFORE starting sync if maintaining v4 behavior

Authentication

  • Set setExpirationHandler callback after initialization
  • Use DittoAuthenticationProvider.development() for playground tokens
  • Remove authentication from identity configuration

Sync API

  • Update ditto.startSync() β†’ ditto.getSync().start()
  • Update ditto.stopSync() β†’ ditto.getSync().stop()
  • Remove disableSyncWithV3() calls

Breaking Changes

  • Set persistenceDirectory if maintaining v4 directory structure
  • Update getPeerKeyString() β†’ getPeerKey()
  • Update isConnectedToDittoCloud() β†’ isConnectedToDittoServer()

Verification

  • Build compiles with zero errors
  • No deprecated API warnings
  • Observers update data immediately
  • Authentication works before sync starts
  • No memory leaks