这是我的数据库:
CREATE TABLE other (
id integer primary key autoincrement not null,
texto text
);
CREATE TABLE tabela (campoid INTEGER primary key autoincrement not null,
camponome text not null, chave int,
foreign key (chave) references other(id));
这是我的课:
@DatabaseTable(tableName = "tabela")
public class Bean {
@DatabaseField(columnName = "campoid", generatedId = true)
private int _id;
@DatabaseField(columnName = "camponome")
private String nome;
@DatabaseField(foreign = true, columnName = "chave", canBeNull = false)
private Part chave;
}
和其他类映射
@DatabaseTable(tableName = "other")
public class Part {
@DatabaseField(generatedId = true, columnName = "id")
private Integer id;
@DatabaseField(columnName = "texto")
private String texto;
}
但是当我保存一个 Bean 对象时,对象“部分”也不会保存:(
Helper helper = OpenHelperManager.getHelper(this, Helper.class);
Dao<Bean, Integer> dao = helper.getDao(Bean.class);
Bean firstBean = new Bean();
firstBean.setNome("first be persisted");
Part part = new Part();
part.setTexto("ANY TEXT");
firstBean.setChave(part);
dao.create(firstBean);
在我的日志中:
07-13 00:25:26.602: D/BaseMappedStatement(3796): 使用语句“INSERT INTO tabela
( camponome
, chave
) VALUES (?,?)”和 2 个参数插入数据,更改了 1 行
任何想法?