Android : Columns and Custom classes in ORMLite

on Friday, August 22, 2014


I'm trying to use ORMLite to store info of my app. My problem is that I have a Class Event, which has some variables and some another classes like custom dates, that have another variables or classes too.


This is my main class:



@DatabaseTable(tableName = "evento")
public class Evento_ORM implements Serializable{

public static final String ID = "_id";
public static final String TIPO_EVENTO = "tipo_evento";
public static final String IDIOMA = "idioma";
public static final String TITULO = "titulo";
public static final String SLUG = "slug";
public static final String UBICACION = "ubicacion";
public static final String DESCRIPCION = "descripcion";
public static final String FECHA_INICIO = "fecha_inicio";
public static final String FECHA_CREACION = "fecha_creacion";
public static final String FECHA_MODIFICACION = "fecha_modificacion";
public static final String FECHA_FIN = "fecha_fin";

@DatabaseField(index = true, columnName = ID)
private int id;

@DatabaseField(canBeNull = false, columnName = TIPO_EVENTO, dataType = DataType.SERIALIZABLE)
private TipoEvento_ORM tipo_evento;

@DatabaseField(canBeNull = false, columnName = IDIOMA, dataType = DataType.SERIALIZABLE)
private Idioma_ORM idioma;

@DatabaseField(canBeNull = false, columnName = TITULO)
private String titulo;

@DatabaseField(canBeNull = false, columnName = SLUG)
private String slug;

@DatabaseField(canBeNull = false, columnName = UBICACION)
private String ubicacion;

@DatabaseField(canBeNull = false, columnName = DESCRIPCION)
private String descripcion;

@DatabaseField(canBeNull = false, columnName = FECHA_INICIO, dataType = DataType.SERIALIZABLE)
private Fecha_ORM fecha_inicio;

@DatabaseField(canBeNull = false, columnName = FECHA_CREACION, dataType = DataType.SERIALIZABLE)
private Fecha_ORM fecha_creacion;

@DatabaseField(canBeNull = false, columnName = FECHA_MODIFICACION, dataType = DataType.SERIALIZABLE)
private Fecha_ORM fecha_modificacion;

@DatabaseField(canBeNull = false, columnName = FECHA_FIN, dataType = DataType.SERIALIZABLE)
private Fecha_ORM fecha_fin;

public Evento_ORM() {
}

public Evento_ORM(int id, TipoEvento_ORM tipo_evento, Idioma_ORM idioma, String titulo, String slug, String ubicacion, String descripcion, Fecha_ORM fecha_inicio, Fecha_ORM fecha_creacion, Fecha_ORM fecha_modificacion, Fecha_ORM fecha_fin) {
this.id = id;
this.tipo_evento = tipo_evento;
this.idioma = idioma;
this.titulo = titulo;
this.slug = slug;
this.ubicacion = ubicacion;
this.descripcion = descripcion;
this.fecha_inicio = fecha_inicio;
this.fecha_creacion = fecha_creacion;
this.fecha_modificacion = fecha_modificacion;
this.fecha_fin = fecha_fin;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getTitulo() {
return titulo;
}

public void setTitulo(String titulo) {
this.titulo = titulo;
}

public String getSlug() {
return slug;
}

public void setSlug(String slug) {
this.slug = slug;
}

public String getUbicacion() {
return ubicacion;
}

public void setUbicacion(String ubicacion) {
this.ubicacion = ubicacion;
}

public String getDescripcion() {
return descripcion;
}

public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}

public Fecha_ORM getFecha_inicio() {
return fecha_inicio;
}

public void setFecha_inicio(Fecha_ORM fecha_inicio) {
this.fecha_inicio = fecha_inicio;
}

public Fecha_ORM getFecha_creacion() {
return fecha_creacion;
}

public void setFecha_creacion(Fecha_ORM fecha_creacion) {
this.fecha_creacion = fecha_creacion;
}

public Fecha_ORM getFecha_modificacion() {
return fecha_modificacion;
}

public void setFecha_modificacion(Fecha_ORM fecha_modificacion) {
this.fecha_modificacion = fecha_modificacion;
}

public Fecha_ORM getFecha_fin() {
return fecha_fin;
}

public void setFecha_fin(Fecha_ORM fecha_fin) {
this.fecha_fin = fecha_fin;
}

public TipoEvento_ORM getTipo_evento() {
return tipo_evento;
}

public void setTipo_evento(TipoEvento_ORM tipo_evento) {
this.tipo_evento = tipo_evento;
}

public Idioma_ORM getIdioma() {
return idioma;
}

public void setIdioma(Idioma_ORM idioma) {
this.idioma = idioma;
}

@Override
public String toString() {
return "Evento{" +
"id=" + id +
", tipo_evento=" + tipo_evento +
", idioma=" + idioma +
", titulo='" + titulo + '\'' +
", slug='" + slug + '\'' +
", ubicacion='" + ubicacion + '\'' +
", descripcion='" + descripcion + '\'' +
", fecha_inicio=" + fecha_inicio +
", fecha_creacion=" + fecha_creacion +
", fecha_modificacion=" + fecha_modificacion +
", fecha_fin=" + fecha_fin +
'}';
}
}


A custom class, for example, date ("FECHA"):



public class Fecha_ORM implements Serializable{

@DatabaseField(canBeNull = false, columnName = "timestamp")
long timestamp;

@DatabaseField(canBeNull = false, columnName = "offset")
int offset;

@DatabaseField(canBeNull = false, columnName = "lastErrors", dataType = DataType.SERIALIZABLE)
Error_ORM lastErrors;

@DatabaseField(canBeNull = false, columnName = "timezoneORM", dataType = DataType.SERIALIZABLE)
Timezone_ORM timezoneORM;

public Fecha_ORM() {
}

public Fecha_ORM(long timestamp, int offset, Error_ORM lastErrors, Timezone_ORM timezoneORM) {
this.timestamp = timestamp;
this.offset = offset;
this.lastErrors = lastErrors;
this.timezoneORM = timezoneORM;
}

public long getTimestamp() {
return timestamp;
}

public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}

public int getOffset() {
return offset;
}

public void setOffset(int offset) {
this.offset = offset;
}

public Error_ORM getLastErrors() {
return lastErrors;
}

public void setLastErrors(Error_ORM lastErrors) {
this.lastErrors = lastErrors;
}

public Timezone_ORM getTimezoneORM() {
return timezoneORM;
}

public void setTimezoneORM(Timezone_ORM timezoneORM) {
this.timezoneORM = timezoneORM;
}

@Override
public String toString() {
return "Fecha_ORM{" +
", timestamp=" + timestamp +
", offset=" + offset +
", lastErrors=" + lastErrors +
", timezoneORM=" + timezoneORM +
'}';
}
}


My problem is that the stored information is right in the variables but in the custom classes It's storing only a column with the value "information" (If you see the ormlite.db with a visor). This is a screenshot, the language is spanish.


Descripcion is Description, fecha_creacion is creation_date, fecha_fin is end_date...


My question is, in the place of the columns fecha_creacion or fecha_fin, that are from a custom class, it shouldn't have the columns with the variables of this custom class???


Screenshot


0 comments:

Post a Comment