This may be a duplicate question but none of the previous answer could work for me. I am trying to store the byte[] in ormlite but I am getting following error.
java.sql.SQLException: ORMLite does not know how to store class [B for field 'imageBytes'. byte[] fields must specify dataType=DataType.BYTE_ARRAY or SERIALIZABLE
I am have already added field type as dataType=DataType.BYTE_ARRAY in java class and in config file also. Here is my Java class.
public class ImageData {
@DatabaseField
private long id;
@DatabaseField(dataType = DataType.BYTE_ARRAY)
byte[] imageBytes;
public ImageData() {
}
public ImageData(long id, byte[] imageBytes) {
this.id = id;
this.imageBytes = imageBytes;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public byte[] getImageBytes() {
return imageBytes;
}
public void setImageBytes(byte[] imageBytes) {
this.imageBytes = imageBytes;
}
public void saveImage(DatabaseHelper dbHelper) throws java.sql.SQLException{
Dao<ImageData,Long> dao = dbHelper.getImageDataDao();
dao.createOrUpdate(this);
}
public static ImageData getImage(DatabaseHelper dbHelper,long id)throws java.sql.SQLException{
Dao<ImageData,Long> dao = dbHelper.getImageDataDao();
ImageData obj = dao.queryForId(id);
return obj;
}
}
And here is my ormlite_config.txt file contents.
# --table-start--
dataClass=com.sample.model.ImageData
tableName=imageData
# --table-fields-start--
# --field-start--
fieldName=id
generatedId=true
allowGeneratedIdInsert=true
# --field-end--
# --field-start--
fieldName=imageBytes
dataPersister = DataType.BYTE_ARRAY
# --field-end--
# --table-fields-end--
# --table-end--
I used dataPersister
as suggested in this answer. Instead of dataPersister I have tried dataType also in my config file. I am not able find the solution. Whats the problem with my code?