【发布时间】:2015-08-13 13:42:06
【问题描述】:
我有 2 个表 Header 和 Binary
标题有点像:
@DatabaseTable(tableName = Header.TABLE_NAME)
public class Header extends Table {
@DatabaseField(
generatedId = true,
columnName = HEADER_ID,
dataType = DataType.LONG_OBJ
)
private Long id;
@ForeignCollectionField(orderColumnName = Binary.BINARY_ORDER, orderAscending = true)
private Collection<Binary> binaries=new ArrayList<Binary>();
}
二进制是:
@DatabaseTable(tableName = Binary.TABLE_NAME)
public class Binary {
@DatabaseField(
generatedId = true,
columnName = BINARY_ID,
dataType = DataType.LONG_OBJ)
private Long id;
@DatabaseField(
columnName = BINARY_HEADER_ID,
foreign = true,
foreignAutoCreate = true,
foreignAutoRefresh = true,
//uniqueCombo = true,
canBeNull = false, //there always must be a link to Item._ID
columnDefinition = "integer constraint fk_4 references `"+ Header.TABLE_NAME+"`(`"+ Header.HEADER_ID+"`) on delete cascade"
)
private Header header=null;
@DatabaseField(
columnName = BINARY_ORDER,
//uniqueCombo = true,
canBeNull = false,
dataType = DataType.INTEGER_OBJ,
defaultValue = "0"
)
private Integer order =0;
@DatabaseField(
columnName = BINARY_CHUNK,
dataType = DataType.BYTE_ARRAY)
private byte[] chunk=null;
}
我的问题出在byte[] chunk 字段中,因为每个块的大小是 1 mb 并且它们的数量几乎是无限的,所以当我阅读 Header 记录时,OrmLite 会隐式读取 Collection<Binary> 具有大量内容的列表 -所以可能会导致内存耗尽。
我应该如何声明我的表来解决这个问题?
【问题讨论】:
-
如何解决 OrmLite 中的大字节 [] 问题:不使用大字节 []
-
请阅读问题。我没有使用巨大的
byte[]- 而是byte[]的列表,这可能是巨大的 -
仍然不使用它......根本不存储 BLOB,而是引用文件......如果 OrmLite 支持延迟加载 - 使用它......无论如何,这是众多原因之一为什么ORMs are bad ...
-
通过设置
eager=false会使数据检索变得懒惰,但这取决于你如何处理Collection<Binary>中的数据 -
我要遍历他们:
for(Binary binary : header.getBinaries()) {}- 如果eager=false有意义吗?
标签: java android sqlite ormlite