# How to define an inner class as a UDT in @Entity and use the UDT?

**URL:** <https://forum.scylladb.com/t/how-to-define-an-inner-class-as-a-udt-in-entity-and-use-the-udt/5001>\
**Category:** ScyllaDB\
**Tags:** data-model, error-message, java-driver, udt\
**Created:** [July 20, 2025, 5:37am UTC](https://forum.scylladb.com/t/how-to-define-an-inner-class-as-a-udt-in-entity-and-use-the-udt/5001 "2025-07-20T05:37:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.scylladb.com/user1/32/1775_2.png) [@user1](https://forum.scylladb.com/u/user1)\
**Post date:** [July 20, 2025, 5:37am UTC](https://forum.scylladb.com/t/how-to-define-an-inner-class-as-a-udt-in-entity-and-use-the-udt/5001/1 "2025-07-20T05:37:33Z")

</div>

How to define an inner class as a UDT in @Entity and use the UDT?

 com.scylladb java-driver-core 4.19.0.1 

```
    <dependency>
        <groupId>com.scylladb</groupId>
        <artifactId>java-driver-mapper-runtime</artifactId>
        <version>4.19.0.1</version>
    </dependency>

    <dependency>
        <groupId>com.scylladb</groupId>
        <artifactId>java-driver-mapper-processor</artifactId>
        <version>4.19.0.1</version>
    </dependency>

```

package com.xgy.entity;

import com.datastax.oss.driver.api.mapper.annotations.\*;  
import com.datastax.oss.driver.api.mapper.entity.naming.NamingConvention;  
import com.fasterxml.jackson.annotation.JsonInclude;  
import com.fasterxml.jackson.annotation.JsonProperty;  
import lombok.AllArgsConstructor;  
import lombok.Data;  
import lombok.NoArgsConstructor;

import java.util.List;  
import java.util.UUID;

import static com.datastax.oss.driver.api.mapper.annotations.SchemaHint.TargetElement.UDT;

@Data  
@AllArgsConstructor  
@NoArgsConstructor  
@JsonInclude(JsonInclude.Include.NON\_NULL)  
@Entity(defaultKeyspace = “novel”)  
@NamingStrategy(convention = NamingConvention.LOWER\_CAMEL\_CASE)  
@CqlName(“character\_”)  
public class Character {

```
@PartitionKey
@CqlName("novel_id")
private UUID novelId;

@ClusteringColumn
@JsonProperty("name")
private String name;

@JsonProperty("summary")
private String summary;

@JsonProperty("storyChain")
@CqlName("story_chain")
private List<StoryNode> storyChain;

@Data
@AllArgsConstructor
@NoArgsConstructor
@SchemaHint(targetElement = UDT)
@NamingStrategy(convention = NamingConvention.LOWER_CAMEL_CASE)
@CqlName("story_node")
public static class StoryNode {
    @JsonProperty("from")
    @CqlName("from_chapter")
    private String from;

    @JsonProperty("to")
    @CqlName("to_chapter")
    private String to;

    @JsonProperty("action")
    @CqlName("action")
    private String action;

    @JsonProperty("context")
    @CqlName("context")
    private String context;
}

```

}

//CREATE TYPE novel.story\_node (  
// from\_chapter text,  
// to\_chapter text,  
// action text,  
// context text  
//);  
//  
//CREATE TABLE novel.character\_ (  
// novel\_id uuid,  
// name text,  
// summary text,  
// story\_chain list\<frozen\<story\_node\>\>,  
// PRIMARY KEY (novel\_id, name)  
//);

Caused by: java.lang.IllegalArgumentException: The CQL ks.table: novel.character\_ defined in the entity class: com.xgy.entity.Character declares type mappings that are not supported by the codec registry:  
Field: story\_chain, Entity Type: com.xgy.entity.Character$StoryNode, CQL type: UDT(novel.story\_node)

---

<div class="post-metadata">

**Author:** ![Gabriel](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.scylladb.com/gabriel/32/60_2.png) [@Gabriel](https://forum.scylladb.com/u/Gabriel)\
**Post date:** [July 28, 2025, 6:04pm UTC](https://forum.scylladb.com/t/how-to-define-an-inner-class-as-a-udt-in-entity-and-use-the-udt/5001/2 "2025-07-28T18:04:05Z")

</div>

The core of your issue is that the ScyllaDB Java driver mapper cannot properly map your inner class (StoryNode) as a UDT when used in your @Entity (Character), resulting in an IllegalArgumentException about unsupported type mappings. This is a common mapping challenge with Cassandra/Scylla Java driver, especially with the use of inner/static nested classes for UDTs.

Key points and steps for a correct mapping setup:

- **UDT classes should be declared as top-level (public) classes**, not inner/nested, for the mapper processor to recognize and generate the correct code. The DataStax and ScyllaDB Java drivers do not support UDTs mapped as nested/inner classes within an entity.
- Your UDT class (StoryNode) needs to be in its own public file and annotated with @UdT, not just @SchemaHint. The annotation processor expects this for code generation.

So, in short -  
Move your UDT Java class (StoryNode) to its own file and annotate it with `@Udt` . Update your Entity to use this top-level class in its list field. This aligns with ScyllaDB/Datastax Java driver requirements and will resolve the mapping exception you encountered
