Question

I have successfully created table with ORMLite, where it looks like it properly added uuid column as an primary key, index, etc.

public class Stat {
    @DatabaseField(id = true)
    protected UUID uuid = UUID.randomUUID();
...

Now, I'd like to be able to use full power of DAO provided and do (Stat is my class to be persisted, getUUID() returns UUID):

Stat statClassInstance = new Stat();
RuntimeExceptionDao<Stat, Integer> statDao = getHelper().getStatDataDao();

statDao.deleteById(statClassInstance.getUUID());

Compiler is giving me an error:

The method deleteById(Integer) in the type RuntimeExceptionDao<Stat,Integer> is not applicable for the arguments (UUID)

What I'm missing is how to use UUID ID's in methods such as deleteById, which accept integer. I've read that UUID as ID was incorporated into ORMLite, but no mention if it went only as far as enabling them to be primary keys, not supporting all those helper methods (queryForId, deleteIds) etc.

Was it helpful?

Solution

In order to use the deleteById(ID) method the Dao<T,ID> should be created accordingly with corresponding parameters which have been identified in your T class. The ID will be interpreted as any type you define in your T class as a primary key. In this particular case it is UUID type and looking at the exception the DAO has been created using Dao<Stat, Integer> and should have been created as follows:

 Dao<Stat, UUID> statDao = DaoManager.createDao(connSource, Stat.class);

hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top