# Embedded

Artifact: [androidx.room3:room3-common](https://developer.android.com/jetpack/androidx/releases/room3) [View Source](https://cs.android.com/search?q=file:androidx/room3/Embedded.kt+class:androidx.room3.Embedded) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

*** ** * ** ***


```
@Target(allowedTargets = [AnnotationTarget.PROPERTY, AnnotationTarget.FIELD, AnnotationTarget.FUNCTION])
@Retention(value = AnnotationRetention.BINARY)
public annotation Embedded
```

<br />

*** ** * ** ***

Marks a property of an `https://developer.android.com/reference/androidx/room3/Entity` or data object to allow nested properties (i.e. properties of the annotated property's class) to be referenced directly in the SQL queries.

If the container is an `https://developer.android.com/reference/androidx/room3/Entity`, these sub properties will be columns in the `https://developer.android.com/reference/androidx/room3/Entity`'s database table.

For example, if you have 2 classes:

```
data class Coordinates (
  val latitude: Double,
  val longitude: Double
)

data class Address (
  val street: String,
  @Embedded
  val coordinates: Coordinates
)
```

Room will consider `latitude` and `longitude` as if they are properties of the `Address` class when mapping an SQLite row to `Address`.

So if you have a query that returns `street, latitude, longitude`, Room will properly construct an `Address` object.

If the `Address` class is annotated with `https://developer.android.com/reference/androidx/room3/Entity`, its database table will have 3 columns: `street`, `latitude` and `longitude`.

If there is a name conflict with the properties of the sub data object and the owner object, you can specify a `https://developer.android.com/reference/androidx/room3/Embedded#prefix()` for the properties of the sub object. Note that the prefix is always applied to sub properties even if they have a `https://developer.android.com/reference/androidx/room3/ColumnInfo` with a specific `name`.

If sub properties of an embedded property has `https://developer.android.com/reference/androidx/room3/PrimaryKey` annotation, they **will not** be considered as primary keys in the owner `https://developer.android.com/reference/androidx/room3/Entity`.

**Nullable Embedded Properties**

When constructing an embedded property that is nullable, if all columns in the row for the properties of the embedded (and its sub properties) are `null` then the embedded property will be set to `null`. Otherwise, it is constructed.

Note that even if you have `https://developer.android.com/reference/androidx/room3/ColumnTypeConverter`s that converts a `null` column into a `non-null`value, if all columns of the embedded property are null, the `https://developer.android.com/reference/androidx/room3/ColumnTypeConverter` will never be used and the embedded property will not be constructed.

This behavior only applies to nullable embedded properties and can be overridden by making the property non-null.

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/room3/Embedded#getPrefix()()` Specifies a prefix to prepend the column names of the properties in the embedded properties. |

## Public methods

### getPrefix

```
public final @NonNull String getPrefix()
```

Specifies a prefix to prepend the column names of the properties in the embedded properties.

For the example above, if we've written:

```
@Embedded(prefix = "loc_")
val coordinates: Coordinates
```

The column names for `latitude` and `longitude` will be `loc_latitude` and `loc_longitude` respectively.

By default, prefix is the empty string.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | The prefix to be used for the properties of the embedded item. |