What annotation is used in Ormlite mapping for Enum as Foreign?

Asked

Viewed 231 times

0

I have the Client class and the Animal Award, where a customer can have 1 or more pets. I would look like this:

@DatabaseTable(tableName = "cliente")
public class Cliente{

@DatabaseField(generateId = true)
private Long id;

@DatabaseField
private String nome;

@????
List<AnimaisEstimacao> animais;

Enum Animaisestimacao

public enum AnimaisEstimacao{
GATO(0);
CACHORRO(1);
PASSARO(2);
OUTROS(3);
//implementacao
}

What would be the Ormlite annotation for the Enum Animalsestimate present in the Client class?

2 answers

0

According to the Ormlite documentation it would look like this:

@DatabaseTable(tableName = "cliente")
public class Cliente{

@DatabaseField(generateId = true)
private Long id;

@DatabaseField
private String nome;

@DatabaseField(dataType = DataType.ENUM_INTEGER)
List<AnimaisEstimacao> animais;
  • But in this case, do I have to map Enum Animalsestimate? Is that possible? Valew

0


A while ago I made a similar code. Try to solve this way:

@DatabaseTable(tableName = "cliente")
public class Cliente{

@DatabaseField(generateId = true)
private Long id;

@DatabaseField
private String nome;

@ForeignCollectionField(foreign = true, eager = true)
Collection<AnimaisEstimacaoCliente> animais;

Then you create a class, for example, "Animaisestimacaocliente" with the fields "Animalestimacao" and "Client" for the relationship. This class must be a representation of a table in the database.

@DatabaseTable(tableName = "animais_estimacao_cliente")
    public class AnimaisEstimacaoCliente{

    @DatabaseField(generateId = true)
    private Long id;

    @ForeignCollectionField(foreign = true )
    private Cliente cliente;


    @DatabaseField(dataType = DataType.ENUM_INT)
    private AnimalEstimacao animal;
}

More information is available at the links:

  • In this case, I have to map the Enum? Valew ae!

  • Sorry, I was unclear in my initial reasoning. I changed the initial post for better understanding.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.