using java8, spring-boot 1.3.5, SOLR 5.5.1
I'm trying to save into the same schema several distinct objects, using SolrCrudRepository . At first, I only had object A, so I used
public interface SolrRepository extends SolrCrudRepository<A , String>
..... //in the service class :
@Autowired
private SolrRepository solrRepository;
....
solrRepository.save(result);
And that was it. Advancing on the project, I was asked to index another object B (related to A from a business pov, but only that) . So, as I did not want to create anther solr repo, I made A and B extends another abstract class AbstractSolrPOJO, and use instead :
public interface SolrRepository extends SolrCrudRepository<AbstractSolrPojo , String>
And that does not work. The autowired of the solr repo fails :
Caused by: java.lang.NullPointerException: null
at org.springframework.data.solr.repository.support.MappingSolrEntityInformation.getIdAttribute(MappingSolrEntityInformation.java:51)
at org.springframework.data.solr.repository.support.SimpleSolrRepository.<init>(SimpleSolrRepository.java:81)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
It seems that spring is looking for the id property, that is defined in both classes using @Field("id") annotation.
Is moving that id to the superclass did not work, I tried with an interface, providing a method to override
@Field("id")
String getIndexId();
but that fails too, but with another error :
Caused by: org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Document is missing mandatory uniqueKey field
So, do I really have to create one repository per object, or is there a "trick" here ?
Thank you