Java ORMLite:外部集合类不包含类异常的外部字段
我试图了解一点关于使用SQLLite实现Android持久化的ORM工具,所以我决定编写一个测试应用程序。 然而,我似乎无法理解这一点。我似乎已经做了所有事情,比如在账户中,OrmLite文档中的订单示例。但是,我不断得到相同的错误: 字段“locations”列名的外部集合类com.example.dataobjects.LocationObject不包含类com.example.dataobjects.TripObject的外部字段 我试图在LocationObject和TripObject之间建立一对多关系 (一个TripObject有多个LocationObjects) 位置对象:Java ORMLite:外部集合类不包含类异常的外部字段,java,android,sql,sqlite,ormlite,Java,Android,Sql,Sqlite,Ormlite,我试图了解一点关于使用SQLLite实现Android持久化的ORM工具,所以我决定编写一个测试应用程序。 然而,我似乎无法理解这一点。我似乎已经做了所有事情,比如在账户中,OrmLite文档中的订单示例。但是,我不断得到相同的错误: 字段“locations”列名的外部集合类com.example.dataobjects.LocationObject不包含类com.example.dataobjects.TripObject的外部字段 我试图在LocationObject和TripObject
@DatabaseTable
public class LocationObject {
private static final String TRIP_ID_FIELD_NAME = "trip_id";
@DatabaseField(generatedId = true)
private int Id;
@DatabaseField
private double latitude;
@DatabaseField
private double longitude;
@DatabaseField(foreign = true, foreignAutoRefresh = true, columnName = TRIP_ID_FIELD_NAME)
private TripObject trip;
public LocationObject()
{
}
public LocationObject(TripObject trip, double latitude, double longitude) {
this.trip = trip;
this.latitude = latitude;
this.longitude = longitude;
}
@Override
public String toString() {
return "LocationObject [Id=" + Id + ", latitude=" + latitude
+ ", longitude=" + longitude + "]";
}
}
TripObject:
@DatabaseTable
public class TripObject {
@DatabaseField(generatedId = true)
private int Id;
@DatabaseField
private String description;
@DatabaseField
private Date createdAt;
@DatabaseField
private int noOfPotholes;
@DatabaseField
private int noOfSpeedbumps;
@ForeignCollectionField
private ForeignCollection<LocationObject> locations;
public TripObject()
{
}
public TripObject(String description, Date createdAt, int noOfPotholes,
int noOfSpeedbumps) {
super();
this.description = description;
this.createdAt = createdAt;
this.noOfPotholes = noOfPotholes;
this.noOfSpeedbumps = noOfSpeedbumps;
this.createdAt = new Date();
}
public ForeignCollection<LocationObject> getLocations()
{
return this.locations;
}
@Override
public String toString() {
return "TripObject [Id=" + Id + ", description=" + description
+ ", createdAt=" + createdAt + ", noOfPotholes=" + noOfPotholes
+ ", noOfSpeedbumps=" + noOfSpeedbumps + ", locations="
+ locations + "]";
}
}
@DatabaseTable
公共类TripObject{
@数据库字段(generatedId=true)
私有int-Id;
@数据库字段
私有字符串描述;
@数据库字段
私人日期创建日期;
@数据库字段
私用内无螺孔;
@数据库字段
私用无速度泵;
@国外收藏场
私人外汇收集地点;
公共对象()
{
}
公共TripObject(字符串描述、创建日期、int noopotholes、,
int noOfSpeedbumps){
超级();
this.description=描述;
this.createdAt=createdAt;
this.noopotholes=noopotholes;
this.noOfSpeedbumps=noOfSpeedbumps;
this.createdAt=新日期();
}
公共外汇集合getLocations()
{
将此文件返回到其他位置;
}
@凌驾
公共字符串toString(){
返回“TripObject[Id=“+Id+”,description=“+description
+,createdAt=“+createdAt+”,noopotholes=“+noopotholes
+“,noOfSpeedbumps=“+noOfSpeedbumps+”,位置=”
+地点+“]”;
}
}
我想做的是测试一些插入和查询,以了解该工具是如何工作的,但我似乎被卡住了
添加活动:
private DatabaseHelper dbHelper;
private void testAddRetrieve() throws SQLException
{
dbHelper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
RuntimeExceptionDao<TripObject, Integer> tripDao = dbHelper.getTripRuntimeExceptionDao();
RuntimeExceptionDao<LocationObject, Integer> locationDao = dbHelper.getLocationRuntimeExceptionDao();
TripObject trip = new TripObject("Test Trip 1", new Date(), 12, 2);
tripDao.create(trip);
TripObject queriedTrip = tripDao.queryBuilder().where().eq("Id", 1).queryForFirst();
Toast.makeText(this,"Trip added: " + queriedTrip.toString(), Toast.LENGTH_LONG).show();
System.out.println("Trip added: " + queriedTrip.toString());
// add
locationDao.create(new LocationObject(trip, 25.5,32.4));
locationDao.create(new LocationObject(trip, 23.5,41.4));
locationDao.create(new LocationObject(trip, 12.5,34.4));
// query
List<LocationObject> locations = locationDao.queryForAll();
Toast.makeText(this, "Locations retrieved: " + locations.toString(), Toast.LENGTH_LONG).show();
System.out.println("Locations retrieved: " + locations.toString());
OpenHelperManager.releaseHelper();
}
私有数据库助手dbHelper;
私有void testAddRetrieve()引发SQLException
{
dbHelper=OpenHelperManager.getHelper(这是DatabaseHelper.class);
RuntimeExceptionDao tripDao=dbHelper.getTripRuntimeExceptionDao();
RuntimeExceptionDao locationDao=dbHelper.getLocationRuntimeExceptionDao();
TripObject跳闸=新TripObject(“测试跳闸1”,新日期(),12,2);
tripDao.create(trip);
TripObject queriedTrip=tripDao.queryBuilder().where().eq(“Id”,1.queryForFirst();
Toast.makeText(这个,“Trip添加了:“+queryedtrip.toString(),Toast.LENGTH\u LONG.show()”;
System.out.println(“添加了Trip:+queryedtrip.toString());
//加
创建(新的LocationObject(trip,25.5,32.4));
创建(新的LocationObject(trip,23.5,41.4));
创建(新的LocationObject(trip,12.5,34.4));
//质疑
List locations=locationDao.queryForAll();
Toast.makeText(这是“检索到的位置:”+Locations.toString(),Toast.LENGTH\u LONG.show();
System.out.println(“检索到的位置:+Locations.toString());
OpenHelperManager.releaseHelper();
}
使用复制