views:

69

answers:

2

Hello. I'm trying to persist the following class with OrmLite:

public class Field {
 @DatabaseField(id = true)
 public String name;

 @DatabaseField(canBeNull = false)
 public FieldType type;

 public Field() {

 }
}

The FieldType is a public enum. The field, corresponding to the type is string in SQLite (is doesn't support enums). When I try to use it, I get the following exception:

INFO [main] (SingleConnectionDataSource.java:244) - Established shared JDBC Connection: org.sqlite.Conn@5224ee
Exception in thread "main" org.springframework.beans.factory.BeanInitializationException: Initialization of DAO failed; nested exception is java.lang.IllegalArgumentException: Unknown field class class enums.FieldType for field FieldType:name=type,class=class orm.Field
 at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:51)
 at orm.FieldDAO.getInstance(FieldDAO.java:17)
 at orm.Field.fromString(Field.java:23)
 at orm.Field.main(Field.java:38)
Caused by: java.lang.IllegalArgumentException: Unknown field class class enums.FieldType for field FieldType:name=type,class=class orm.Field
 at com.j256.ormlite.field.FieldType.<init>(FieldType.java:54)
 at com.j256.ormlite.field.FieldType.createFieldType(FieldType.java:381)
 at com.j256.ormlite.table.DatabaseTableConfig.fromClass(DatabaseTableConfig.java:82)
 at com.j256.ormlite.dao.BaseJdbcDao.initDao(BaseJdbcDao.java:116)
 at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:48)
 ... 3 more

So how do I tell OrmLite, values on the Java side are from an enum?

A: 

You should have a look at the source code and check of the String or int field type are handled and extend the mapping code accordingly.

Aaron Digulla
ormlite source code?
htf
Which ormlite are you talking about? http://code.google.com/p/ormlite/?
Aaron Digulla
no, http://ormlite.sourceforge.net/ sorry about not specifying
htf
+2  A: 

The answer is in the future to contact the developer -- me. You can subscribe to the ORMLite project on sourceforge and submit a forum question or bug. Also, my contact form is at the bottom of my home page: http://256.com/gray/


So sorry about this problem. Not having Enum support was a huge miss that is embarrassing. This has been fixed and the 2.2 release that I just put out now handles persisting enums either as the VARCHAR enum name (default) or as the ordinal INTEGER.

https://sourceforge.net/projects/ormlite/files/

Documentation about the types persisted with the new Enum type at the bottom:

http://ormlite.sourceforge.net/javadoc/doc-files/ormlite_1.html#SEC7

Please let me know if this does not solve your problems or if ORMLite has any other missing features ASAP.

Gray
Thanks, you're doing great job, anyways do you think it would be better to contact you via the form or this site? I guess the latter could save your time when people google for what they want first
htf
I could have easily missed your question which I found out of the blue yesterday. Please _subscribe_ to the ORMLite project on sourceforge and you can submit forum questions and stuff. That's the best way. I'd also appreciate it if you rated the ORMLite project. You can also contact me via the my site as well.
Gray