# Embedded

Summary:[Methods](https://developer.android.com/reference/android/arch/persistence/room/Embedded#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/arch/persistence/room/Embedded#inhmethods)  

# Embedded

| The`android.arch`Architecture Components packages are no longer maintained. They have been superseded by the corresponding[androidx.\*](https://developer.android.com/jetpack/androidx/migrate)packages. See[androidx.room.Embedded](https://developer.android.com/reference/androidx/room/Embedded)instead.

`
public


abstract
@interface
Embedded
`  
`


implements

Annotation


`

|----------------------------------------|
| android.arch.persistence.room.Embedded |

<br />

*** ** * ** ***

Can be used as an annotation on a field of an[Entity](https://developer.android.com/reference/android/arch/persistence/room/Entity)or`Pojo`to signal that nested fields (i.e. fields of the annotated field's class) can be referenced directly in the SQL queries.

If the container is an[Entity](https://developer.android.com/reference/android/arch/persistence/room/Entity), these sub fields will be columns in the[Entity](https://developer.android.com/reference/android/arch/persistence/room/Entity)'s database table.

For example, if you have 2 classes:  

```
   public class Coordinates {
       double latitude;
       double longitude;
   }
   public class Address {
       String street;
       @Embedded
       Coordinates coordinates;
   }
 
```
Room will consider`latitude`and`longitude`as if they are fields 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`class.

If the`Address`class is annotated with[Entity](https://developer.android.com/reference/android/arch/persistence/room/Entity), its database table will have 3 columns:`street, latitude, longitude`

If there is a name conflict with the fields of the sub object and the owner object, you can specify a[prefix()](https://developer.android.com/reference/android/arch/persistence/room/Embedded#prefix())for the items of the sub object. Note that prefix is always applied to sub fields even if they have a[ColumnInfo](https://developer.android.com/reference/android/arch/persistence/room/ColumnInfo)with a specific`name`.

If sub fields of an embedded field has[PrimaryKey](https://developer.android.com/reference/android/arch/persistence/room/PrimaryKey)annotation, they**will not** be considered as primary keys in the owner[Entity](https://developer.android.com/reference/android/arch/persistence/room/Entity).

When an embedded field is read, if all fields of the embedded field (and its sub fields) are`null`in the[Cursor](https://developer.android.com/reference/android/database/Cursor.html), it is set to`null`. Otherwise, it is constructed.

Note that even if you have[TypeConverter](https://developer.android.com/reference/android/arch/persistence/room/TypeConverter)s that convert a`null`column into a`non-null`value, if all columns of the embedded field in the[Cursor](https://developer.android.com/reference/android/database/Cursor.html)are null, the[TypeConverter](https://developer.android.com/reference/android/arch/persistence/room/TypeConverter)will never be called and the embedded field will not be constructed.

You can override this behavior by annotating the embedded field with[NonNull](https://developer.android.com/reference/android/support/annotation/NonNull).

## Summary

|                                                                                            ### Public methods                                                                                             ||
|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` String` | ` `[prefix](https://developer.android.com/reference/android/arch/persistence/room/Embedded#prefix())`() ` Specifies a prefix to prepend the column names of the fields in the embedded fields. |

| ### Inherited methods |
|-----------------------|---|
| From interface` java.lang.annotation.Annotation ` |-----------------------------------------|-------------------------| | ` abstract Class<? extends Annotation>` | ` annotationType() `    | | ` abstract boolean`                     | ` equals(Object arg0) ` | | ` abstract int`                         | ` hashCode() `          | | ` abstract String`                      | ` toString() `          | ||

## Public methods

### prefix

```
String prefix ()
```

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

For the example above, if we've written:  

```
   @Embedded(prefix = "foo_")
   Coordinates coordinates;
 
```
The column names for`latitude`and`longitude`will be`foo_latitude`and`foo_longitude`respectively.

By default, prefix is the empty string.

<br />

|                                   Returns                                   ||
|----------|-------------------------------------------------------------------|
| `String` | The prefix to be used for the fields of the embedded item. <br /> |

-

  ## Annotations

  - [ColumnInfo](https://developer.android.com/reference/android/arch/persistence/room/ColumnInfo)
  - [ColumnInfo.Collate](https://developer.android.com/reference/android/arch/persistence/room/ColumnInfo.Collate)
  - [ColumnInfo.SQLiteTypeAffinity](https://developer.android.com/reference/android/arch/persistence/room/ColumnInfo.SQLiteTypeAffinity)
  - [Dao](https://developer.android.com/reference/android/arch/persistence/room/Dao)
  - [Database](https://developer.android.com/reference/android/arch/persistence/room/Database)
  - [Delete](https://developer.android.com/reference/android/arch/persistence/room/Delete)
  - [Embedded](https://developer.android.com/reference/android/arch/persistence/room/Embedded)
  - [Entity](https://developer.android.com/reference/android/arch/persistence/room/Entity)
  - [ForeignKey](https://developer.android.com/reference/android/arch/persistence/room/ForeignKey)
  - [ForeignKey.Action](https://developer.android.com/reference/android/arch/persistence/room/ForeignKey.Action)
  - [Ignore](https://developer.android.com/reference/android/arch/persistence/room/Ignore)
  - [Index](https://developer.android.com/reference/android/arch/persistence/room)
  - [Insert](https://developer.android.com/reference/android/arch/persistence/room/Insert)
  - [OnConflictStrategy](https://developer.android.com/reference/android/arch/persistence/room/OnConflictStrategy)
  - [PrimaryKey](https://developer.android.com/reference/android/arch/persistence/room/PrimaryKey)
  - [Query](https://developer.android.com/reference/android/arch/persistence/room/Query)
  - [RawQuery](https://developer.android.com/reference/android/arch/persistence/room/RawQuery)
  - [Relation](https://developer.android.com/reference/android/arch/persistence/room/Relation)
  - [SkipQueryVerification](https://developer.android.com/reference/android/arch/persistence/room/SkipQueryVerification)
  - [Transaction](https://developer.android.com/reference/android/arch/persistence/room/Transaction)
  - [TypeConverter](https://developer.android.com/reference/android/arch/persistence/room/TypeConverter)
  - [TypeConverters](https://developer.android.com/reference/android/arch/persistence/room/TypeConverters)
  - [Update](https://developer.android.com/reference/android/arch/persistence/room/Update)
-

  ## Classes

  - [DatabaseConfiguration](https://developer.android.com/reference/android/arch/persistence/room/DatabaseConfiguration)
  - [InvalidationTracker](https://developer.android.com/reference/android/arch/persistence/room/InvalidationTracker)
  - [InvalidationTracker.Observer](https://developer.android.com/reference/android/arch/persistence/room/InvalidationTracker.Observer)
  - [Room](https://developer.android.com/reference/android/arch/persistence/room/Room)
  - [RoomDatabase](https://developer.android.com/reference/android/arch/persistence/room/RoomDatabase)
  - [RoomDatabase.Builder](https://developer.android.com/reference/android/arch/persistence/room/RoomDatabase.Builder)
  - [RoomDatabase.Callback](https://developer.android.com/reference/android/arch/persistence/room/RoomDatabase.Callback)
  - [RoomDatabase.MigrationContainer](https://developer.android.com/reference/android/arch/persistence/room/RoomDatabase.MigrationContainer)
  - [RoomWarnings](https://developer.android.com/reference/android/arch/persistence/room/RoomWarnings)
  - [RxRoom](https://developer.android.com/reference/android/arch/persistence/room/RxRoom)
-

  ## Enums

  - [RoomDatabase.JournalMode](https://developer.android.com/reference/android/arch/persistence/room/RoomDatabase.JournalMode)
-

  ## Exceptions

  - [EmptyResultSetException](https://developer.android.com/reference/android/arch/persistence/room/EmptyResultSetException)