Hey Tim, long time no talk to! The UUID type isn't a native UUID like you're expecting. It's a String that gets validated as a UUID at input time. You're probably being saved by the .toString() method at index time, but that's not going to help you during retrieval.
You're probably going to want to treat them as Strings in your bean, with convenience methods to get native Java UUID objects in and out. Michael Della Bitta ------------------------------------------------ Appinions 18 East 41st Street, 2nd Floor New York, NY 10017-6271 www.appinions.com Where Influence Isn’t a Game On Mon, Feb 4, 2013 at 10:03 AM, Tim Robertson <timrobertson...@gmail.com> wrote: > Hi all, > > > I am trying to use solrj with UUIDs but they are coming back as Strings in > the SolrDocument so the reflection fails on the "getBeans" method. > > > In my POJO: > > public class SearchableNode { > > @Field > > private UUID key; > > > @Field > > private String title; > > > //... with getters and setters > > } > > > > And in my schema.xml I have: > > <fieldType name="uuid" class="solr.UUIDField"/> > > ... > > <field name="key" type="uuid" indexed="true" stored="true" > required="true"/> > > <field name="title" type="string" indexed="true" stored="true" > required="true"/> > > > > In my code I can add the objects using > > SearchableNode node = getNode(); > > solr.addBean(node); > > > > But this fails: > > SolrQuery solrQuery = new SolrQuery().setQuery("*"); > > QueryResponse rsp = solr.query(solrQuery); > > rsp.getBeans(SearchableNode.class); > > > > > > With the following: > > org.apache.solr.client.solrj.beans.BindingException: Could not instantiate > object of class org.gbif.registry.search.SearchableNode > > at > org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBean(DocumentObjectBinder.java:68) > > at > org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBeans(DocumentObjectBinder.java:47) > > at > org.apache.solr.client.solrj.response.QueryResponse.getBeans(QueryResponse.java:480) > > at org.gbif.registry.search.SOLRTest.main(SOLRTest.java:37) > > Caused by: org.apache.solr.client.solrj.beans.BindingException: Exception > while setting value : efb6dcef-eb58-4b0d-b34f-c13855d6c2f6 on private > java.util.UUID org.gbif.registry.search.SearchableNode.key > > at > org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.set(DocumentObjectBinder.java:370) > > at > org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.inject(DocumentObjectBinder.java:353) > > at > org.apache.solr.client.solrj.beans.DocumentObjectBinder.getBean(DocumentObjectBinder.java:64) > > ... 3 more > > Caused by: java.lang.IllegalArgumentException: Can not set java.util.UUID > field org.gbif.registry.search.SearchableNode.key to java.lang.String > > at > sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146) > > at > sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150) > > at > sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63) > > at java.lang.reflect.Field.set(Field.java:657) > > at > org.apache.solr.client.solrj.beans.DocumentObjectBinder$DocField.set(DocumentObjectBinder.java:364) > > ... 5 more > > When I step through it with a debugger, I see that the SolrDocument is > already set with String value for the key so of course it fails. > > > Can anyone advise me (a newbie) what I have done wrong please? > > Many thanks! > > Tim