我的一个业务对象有一个 CommunicationMedium 类型的成员,它是一个枚举。
public enum CommunicationMedium {
EMAIL,
PHONE,
MOBILE,
FACSIMILE,
HOMEPAGE
}
名为 CommunicationData 的业务对象是这样注释的。
@DatabaseTable(tableName="store_communication_data")
public class CommunicationData{
public static final String STORE_ID ="store_id";
public static final String TABLE_NAME = "store_communication_data";
public static final String MEDIUM_COLUMN_NAME = "medium";
public static final String VALUE_COLUMN_NAME = "value";
@DatabaseFieldSimple(canBeNull=false, columnName=STORE_ID)
@DatabaseFieldForeign(foreign=true)
private Store store;
@DatabaseFieldSimple(canBeNull=false, columnName=MEDIUM_COLUMN_NAME, defaultValue="CommunicationMedium.EMAIL")
@DatabaseFieldOther(dataType=DataType.ENUM_STRING)
private CommunicationMedium communicationMedium;
@DatabaseFieldSimple(canBeNull=false, columnName=VALUE_COLUMN_NAME)
private String value;
...
}
第一次访问数据库助手时,CommunicationData
应创建类的表时引发以下异常。该列的默认值似乎有问题medium
。
java.sql.SQLException: SQL statement failed: CREATE TABLE `store_communication_data` (`medium` __ormlite__ no default value string was specified , `store_id` INTEGER NOT NULL , `value` VARCHAR NOT NULL )
at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
at com.j256.ormlite.table.TableUtils.doStatements(TableUtils.java:458)
at com.j256.ormlite.table.TableUtils.doCreateTable(TableUtils.java:436)
at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:223)
at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:53)
...
Caused by: java.sql.SQLException: Problems executing Android statement: CREATE TABLE `store_communication_data` (`medium` __ormlite__ no default value string was specified , `store_id` INTEGER NOT NULL , `value` VARCHAR NOT NULL )
at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
at com.j256.ormlite.android.AndroidCompiledStatement.runUpdate(AndroidCompiledStatement.java:71)
at com.j256.ormlite.table.TableUtils.doStatements(TableUtils.java:452)
...
Caused by: android.database.sqlite.SQLiteException: near "string": syntax error: , while compiling: CREATE TABLE `store_communication_data` (`medium` __ormlite__ no default value string was specified , `store_id` INTEGER NOT NULL , `value` VARCHAR NOT NULL )
at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1026)
...