title: GreenDAO on Android: Byte Array as Primary Key / Building Query Containing Where Clause on Byte Array Property
body: <p>I am currently trying to select entries using a query containing a where condition on a (byte array) property. This property/column contains a serialized UUID. Unfortunately I currently cannot change the data type of this column, as the database is created and synced by a separate module which only works properly with the current implementation. As greenDao cannot handle byte arrays as primary keys properly I am trying to work around this issue somehow. Creating my own selection queries etc. would be a solution
  The property is defined during greenDAO generation as:</p>
  
  <pre><code>Entity randomEntity = schema.addEntity("RandomEntity");
  ...
  randomEntity.addByteArrayProperty("RandomProperty"); 
  </code></pre>
  
  <p><br>The query is built using following line:</p>
  
  <pre><code>Query query = this.mRandomEntityDao.queryBuilder().where(RandomEntityDao.Properties.RandomProperty.eq(randomByteArray)).build();
  </code></pre>
  
  <p><br>Unfortunately I get following error with this operation:</p>
  
  <pre><code>de.greenrobot.dao.DaoException: Illegal value: found array, but simple object required
  at de.greenrobot.dao.query.WhereCondition$PropertyCondition.checkValueForType(WhereCondition.java:75)
  ...
  </code></pre>
  
  <p><br/><b>Is this where condition is simply not supported by greenDAO or am I missing something crucial?</b> Unfortunately I cannot use another datatype for this certain property.
  <br/><br/>
  <strong>Edit:</strong></p>
  
  <p>My current workaround goes as follows:<Br>
  As greenDao can handle primary keys which are strings (up to a certain point) and UUIDs can also be represented by this data type I altered the existing tables and added following columns:</p>
  
  <pre><code>db.execSQL("ALTER TABLE 'RANDOMTABLE' ADD COLUMN '_GREENID' TEXT;");
  </code></pre>
  
  <p><br>The sync module is ignoring this column so there shouldn’t be any issues with that. Then I created a trigger mapping the serialized UUID in the <code>ID</code> column to the new <code>_GREENID</code> column:</p>
  
  <pre><code>db.execSQL("CREATE TRIGGER randomtableGreen AFTER INSERT ON 'RANDOMTABLE' BEGIN " + 
  "UPDATE 'RANDOMTABLE' SET '_GREENID' = HEX(NEW.ID) WHERE 'RANDOMTABLE'.ID = NEW.ID; " +
  "END;");
  </code></pre>
  
  <p><br>Finally I run an update on the table in case they already contained some entries prior to the creation of the trigger:</p>
  
  <pre><code>db.execSQL("UPDATE 'RANDOMTABLE' SET '_GREENID' = HEX(ID) WHERE '_GREENID' &lt;&gt; '';");
  </code></pre>