j256 / ormlite-android

ORMLite Android functionality used in conjunction with ormlite-core
http://ormlite.com/
ISC License
1.59k stars 367 forks source link

Join problem with query #46

Open grmaciel opened 9 years ago

grmaciel commented 9 years ago

I'm doing some join tests and i'm having a join getting the wrong column

Here are my models:

public class PontoVenda extends BaseModel {
@DatabaseField(canBeNull = false)
private Integer codigo;
@DatabaseField(canBeNull = false)
private String razao;
@DatabaseField(canBeNull = false)
private String nome;
@DatabaseField(canBeNull = false)
private String endereco;
@DatabaseField
private String cep;
@DatabaseField(canBeNull = false, foreign = true)
private Cdd cdd;
@DatabaseField(canBeNull = true, foreign = true)
private Bairro bairro;
@DatabaseField(canBeNull = true, foreign = true)
private Municipio municipio;
}

public class Cdd extends BaseModel {
@DatabaseField(canBeNull = false)
private String descricao;
@DatabaseField(canBeNull = false)
private String uuid;
@DatabaseField(canBeNull = false)
private Integer unb;
@DatabaseField(canBeNull = false, foreign = true)
private Geo geo;
}

My queryBuilder joins:

QueryBuilder<PontoVenda, ?> pdvQb =       DaoManager.createDao(getPdvRepository().getDB().getConnectionSource(),
            PontoVenda.class).queryBuilder();
    QueryBuilder<Cdd, ?> cddQb = DaoManager.createDao(getPdvRepository().getDB().getConnectionSource(),
            Cdd.class).queryBuilder();

This is the sql output from the prepareStatementString

﹕ SELECT pontovenda.* FROM pontovenda INNER JOIN cdd ON pontovenda.bairro_id = cdd.id

Why is he joining a column that does not relate with the Cdd class at all? Am im doing something wrong?

Thank you,

pzmudzinski commented 9 years ago

Could you post your BaseModel class?

grmaciel commented 9 years ago

Base Model:

public abstract class BaseModel {
    @DatabaseField(
        generatedId = true,
        allowGeneratedIdInsert = true,
        canBeNull = false
    )
    protected Long id;
    @DatabaseField(
        canBeNull = true
    )
    protected Date dataCriacao;

    public BaseModel() {
    }

    public Date getDataCriacao() {
        return this.dataCriacao;
    }

    public void setDataCriacao(Date dataCriacao) {
        this.dataCriacao = dataCriacao;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}
j256 commented 8 years ago

Can you post the complete query code? How is the QueryBuilder used?