ormlite DataType.ENUM_STRING 给我“对于数据持久器无效”
你好,我正在使用 ORMLite 4.33。
我有一个实体类,在尝试 destroyTable 时出现错误:
E/AndroidRuntime(6715): java.lang.IllegalArgumentException: Field class
java.lang.String for field FieldType:name=udm,class=Prodotti is not valid
for data persister com.j256.ormlite.field.types.EnumStringType@40a3a2e0
这是我运行 DatabaseConfigUtil 来更新 ormlite_config.txt 的类
@DatabaseTable(tableName = "Prodotti")
public class Prodotti extends BaseDaoEnabled{
....
@DatabaseField(dataType = DataType.ENUM_STRING,
columnDefinition="VARCHAR(100) DEFAULT NULL")
//also tried @DatabaseField(dataType = DataType.ENUM_STRING)
private String udm;
...
}
,现在我认为唯一的解决方案是将字段的类型更改为 String
Hello i am using ORMLite 4.33.
I have an entity class that gives me an error when trying to destroyTable:
E/AndroidRuntime(6715): java.lang.IllegalArgumentException: Field class
java.lang.String for field FieldType:name=udm,class=Prodotti is not valid
for data persister com.j256.ormlite.field.types.EnumStringType@40a3a2e0
here is the class
@DatabaseTable(tableName = "Prodotti")
public class Prodotti extends BaseDaoEnabled{
....
@DatabaseField(dataType = DataType.ENUM_STRING,
columnDefinition="VARCHAR(100) DEFAULT NULL")
//also tried @DatabaseField(dataType = DataType.ENUM_STRING)
private String udm;
...
}
I runned DatabaseConfigUtil to update the ormlite_config.txt, right now i'm thinking the only solution is to change the type of the field to String
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ORMLite 不支持仅受几种数据库类型支持的数据库 SQL 枚举列。
ENUM_STRING
应该保留枚举类型。类似于:默认情况下,ORMLite 会将枚举保留为
VARCHAR
SQL 字段中的字符串值(RED、GREEN、BLUE)。如果您有一个 String 字段,那么您应该将其保留为 STRING 类型。如果您想存储其值,也可以使用DataType.ENUM_INTEGER
,但出于向后兼容性的原因,不建议这样做。如果您编辑问题以更好地解释您想要完成的任务,我可以编辑我的答案以提供更多信息。
ORMLite does not support database SQL enum columns which are only supported by a couple of database types. The
ENUM_STRING
is supposed to persist an enum type. Something like:By default, ORMLite will then persist the enum as it's string value (RED, GREEN, BLUE) in a
VARCHAR
SQL field. If you have aString
field then you should just let it be persisted as aSTRING
type. You can also use theDataType.ENUM_INTEGER
if you want to store its value instead but that is not recommended for backwards compatibility reasons.If you edit your questions to better explain what you are trying to accomplish, I can edit my answer to provide more information.