Class to Table Mapping¶
When you use custom classes in your application for data persistence, Backendless maps the database table names to the names of the classes. For example, the following code is automatically mapped to the Person
table:
package com.sample;
public class Person
{
public String objectId;
public String name;
public int age;
}
The Person
table in the Backendless database:
When the name of the class is different than the name of the corresponding table in the database, it is necessary to customize the mapping. This can be achieved with the following API:
Backendless.Data.mapTableToClass( String YOUR-TABLE, Class clazz )
where:
Argument | Description |
---|---|
YOUR-TABLE |
name of the table to map to a class. |
clazz |
reference to a class to map to the table. |
The API is not necessary if the class name is the same as the table name. The only exception to this rule is when your application retrieves related objects using the "Custom Class" approach. In this case, if application should establish mappings between client-side classes and the related (children) tables. For example, consider the following schema:
Order (parent) table:
OrderItem (child) table:
If any related OrderItem objects are retrieved along the parent Order object (via auto-load or single-step relation retrieval), then the application must establish a mapping for the OrderItem table before the data is retrieved.
Backendless.Data.mapTableToClass( "OrderItem", OrderItem.class )