Java 使用ORMLite按属性查询持久对象的关系。
我刚刚开始阅读关于ORMLite的文章,所以我还是个初学者。 据我所知,我可以使用对象的任何持久属性查询对象 例如,如果我有以下课程:Java 使用ORMLite按属性查询持久对象的关系。,java,ormlite,Java,Ormlite,我刚刚开始阅读关于ORMLite的文章,所以我还是个初学者。 据我所知,我可以使用对象的任何持久属性查询对象 例如,如果我有以下课程: @DatabaseTable public class Bill { @DatabaseField String code; Client client; List<Item> items; } @DatabaseTable class Client { @DatabaseField String name; } @Databa
@DatabaseTable
public class Bill {
@DatabaseField String code;
Client client;
List<Item> items;
}
@DatabaseTable
class Client {
@DatabaseField String name;
}
@DatabaseTable
class Item {
@DatabaseField String name;
}
我的问题是:在ORMLite中,编写在模型对象的传递关系中具有条件的查询的推荐方法是什么?例如“包含具有特定名称的特定项目的所有账单”?或者“所有购买了具有特定名称的商品的客户”
提前谢谢 读取外部对象字段和 你们的关系将是:
@DatabaseTable(tableName = "bills")
public class Bill {
public static final String ACCOUNT_ID_FIELD_NAME = "client_id";
@DatabaseField(generatedId = true)
private int id;
@DatabaseField(foreign = true, columnName = ACCOUNT_ID_FIELD_NAME)
private Client client;
@DatabaseField
private String code;
Client client;
List<Item> items;
public Bill(){
}
public Bill(Client client, String code){
this.client = client;
this.code = code;
}
public int getId(){
return this.id;
}
public String getCode(){
return this.code;
}
}
@DatabaseTable(tableName = "clients")
class Client {
public static final String NAME_FIELD_NAME = "name";
public Client() {
// all persisted classes must define a no-arg constructor with at least package visibility
}
public Client(String name) {
this.name = name;
}
@DatabaseField(generatedId = true)
private int id;
@DatabaseField(columnName = NAME_FIELD_NAME, canBeNull = false)
private String name;
public int getId(){
return this.id;
}
public String getName(){
return this.name;
}
}
@DatabaseTable(tableName=“bills”)
公共课条例草案{
公共静态最终字符串帐户\u ID\u字段\u NAME=“客户\u ID”;
@数据库字段(generatedId=true)
私有int-id;
@数据库字段(foreign=true,columnName=ACCOUNT\u ID\u FIELD\u NAME)
私人客户;
@数据库字段
私有字符串码;
客户;
清单项目;
公共法案(){
}
公共票据(客户端,字符串代码){
this.client=client;
this.code=代码;
}
公共int getId(){
返回此.id;
}
公共字符串getCode(){
返回此.code;
}
}
@数据库表(tableName=“clients”)
类客户端{
公共静态最终字符串名称\u字段\u NAME=“NAME”;
公共客户机(){
//所有持久化类必须定义至少具有包可见性的无参数构造函数
}
公共客户端(字符串名称){
this.name=名称;
}
@数据库字段(generatedId=true)
私有int-id;
@DatabaseField(columnName=NAME\u FIELD\u NAME,canBeNull=false)
私有字符串名称;
公共int getId(){
返回此.id;
}
公共字符串getName(){
返回此.name;
}
}
有关更多信息,请参阅
@DatabaseTable(tableName = "bills")
public class Bill {
public static final String ACCOUNT_ID_FIELD_NAME = "client_id";
@DatabaseField(generatedId = true)
private int id;
@DatabaseField(foreign = true, columnName = ACCOUNT_ID_FIELD_NAME)
private Client client;
@DatabaseField
private String code;
Client client;
List<Item> items;
public Bill(){
}
public Bill(Client client, String code){
this.client = client;
this.code = code;
}
public int getId(){
return this.id;
}
public String getCode(){
return this.code;
}
}
@DatabaseTable(tableName = "clients")
class Client {
public static final String NAME_FIELD_NAME = "name";
public Client() {
// all persisted classes must define a no-arg constructor with at least package visibility
}
public Client(String name) {
this.name = name;
}
@DatabaseField(generatedId = true)
private int id;
@DatabaseField(columnName = NAME_FIELD_NAME, canBeNull = false)
private String name;
public int getId(){
return this.id;
}
public String getName(){
return this.name;
}
}