Announcement Announcement Module
Collapse
No announcement yet.
Spring Roo and Apache Solr Add On Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Roo and Apache Solr Add On

    Hi,

    I am integrating Apache Solr and Spring Roo 1.1.5. I have a Bean definition like this.

    public class Address {

    @Field("address.firstline_s")
    private String firstLine;
    @Field("address.secondline_s")
    private String secondLine;
    @Field("address.thirdline_s")
    private String thirdLine;
    @OneToOne
    @JoinColumn(name = "id")
    @Field("address.city_t")
    private City city;
    }

    public class City {
    @Field("city.name_s")
    private String name;
    }

    I am indexing the Bean as Solr Document in the Apache Solr Search. To show the list of documents from Search server i do the following:
    Address.search("*").getBeans(Address.class)

    I find that i able to see the right values in firstline,secondline,thirdline fields but Spring Roo is unable to map values to City object.

    I get the following exception:

    Exception while setting value : Id: 1, Name: city1, Version: 0 on private com.ebooking.resource.identify.info.City com.ebooking.resource.identify.info.Address.city

    There is a problem in mapping to nested objects. Is this a limitation or a bug? What are the alternate solutions for this? Is denormalizing objects a solution, i wouldn't want to go down that path.

    Any thoughts?

    Regards,
    Anand

  • #2
    Hi,

    I have figured out a solution for this:
    My understanding is this that this is a limitation of this integration that it cannot get to mapping out nested objects in an object. Maybe the showing search results may not be performant if there are nested objects. It may better to go for one level of object.

    From a design perspective also it may useful to separate out creation bean from how it is shown in a screen. You may want to show a view which may not have all the fields that you would use during creation. I created a notion of a Data Transfer Object with a definition like this:

    package com.ebooking.resource.identify.info;

    import org.springframework.roo.addon.entity.RooEntity;
    import org.springframework.roo.addon.javabean.RooJavaBean ;
    import org.springframework.roo.addon.tostring.RooToString ;
    import javax.persistence.OneToOne;
    import javax.persistence.JoinColumn;
    import org.apache.solr.client.solrj.beans.Field;


    @RooJavaBean
    @RooToString

    public class AddressDTO {
    @Field("id")
    private String id;
    @Field("address.firstline_s")
    private String firstLine;
    @Field("address.secondline_s")
    private String secondLine;
    @Field("address.thirdline_s")
    private String thirdLine;
    @Field("address.city_t")
    private String city;
    @Field("address.state_t")
    private String state;
    @Field("address.area_t")
    private String area;
    }

    It worked like a charm. I am now trying to see if rendering results from Apache Solr can become part of code generation from Roo Shell. Currently the code that is generated for this integration is only indexing of the document in search server during creation of record.

    Regards,
    Anand

    Comment

    Working...
    X