Implementation:Datahub project Datahub HasDomains Mixin
| Knowledge Sources | |
|---|---|
| Domains | Java_SDK, Metadata_Management |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Description
HasDomains is a mixin interface in the DataHub Java SDK V2 that provides domain assignment operations for entities. Entities implementing this interface can be assigned to DataHub domains for organizational governance. The interface supports setting a single domain, removing specific domains, clearing all domains, and retrieving domain assignments.
Mutation methods such as removeDomain() and clearDomains() are annotated with @RequiresMutable and enforce that the entity is not in a read-only state.
The interface uses the self-bounded generic pattern (T extends Entity & HasDomains<T>) for fluent API chaining.
Usage
Entity classes implement this interface to gain domain management capabilities. The setDomain() method replaces all existing domains with a single domain, while removeDomain() removes a specific one. Read operations (getDomain() and getDomains()) use lazy aspect loading.
Code Reference
Source Location
metadata-integration/java/datahub-client/src/main/java/datahub/client/v2/entity/HasDomains.java
Signature
public interface HasDomains<T extends Entity & HasDomains<T>> {
@Nonnull
default T setDomain(@Nonnull String domainUrn)
@Nonnull
default T setDomain(@Nonnull Urn domain)
@Nonnull
default T removeDomain(@Nonnull String domainUrn)
@RequiresMutable
@Nonnull
default T removeDomain(@Nonnull Urn domain)
@RequiresMutable
@Nonnull
default T clearDomains()
@Nullable
default Urn getDomain()
@Nullable
default List<Urn> getDomains()
}
Import
import datahub.client.v2.entity.HasDomains;
I/O Contract
Inputs
| Method | Parameter | Type | Description |
|---|---|---|---|
| setDomain | domainUrn |
String |
URN string of the domain to assign |
| setDomain | domain |
Urn |
URN object of the domain to assign |
| removeDomain | domainUrn |
String |
URN string of the domain to remove |
| removeDomain | domain |
Urn |
URN object of the domain to remove |
Outputs
| Method | Return Type | Description |
|---|---|---|
| setDomain | T |
The entity itself for fluent chaining |
| removeDomain | T |
The entity itself for fluent chaining |
| clearDomains | T |
The entity itself for fluent chaining |
| getDomain | Urn (nullable) |
The first domain URN, or null if none present
|
| getDomains | List<Urn> (nullable) |
All domain URNs, or null if none present
|
Exceptions:
InvalidUrnException- thrown if a string URN cannot be parsedReadOnlyEntityException- thrown by@RequiresMutablemethods on read-only entities
Usage Examples
Dataset dataset = Dataset.builder()
.platform("snowflake")
.name("my_table")
.build();
// Set a domain
dataset.setDomain("urn:li:domain:engineering");
// Read the domain back
Urn domain = dataset.getDomain();
// Remove a domain (requires mutable entity)
dataset.removeDomain("urn:li:domain:engineering");
// Clear all domains
dataset.clearDomains();
Related Pages
- Datahub_project_Datahub_HasContainer_Mixin - Mixin for container hierarchy
- Datahub_project_Datahub_HasOwners_Mixin - Mixin for ownership management
- Datahub_project_Datahub_HasGlossaryTerms_Mixin - Mixin for glossary term assignment
- Datahub_project_Datahub_ReadOnlyEntityException - Exception thrown on read-only mutation attempts