This should be a simple question about something that I'm probably missing from the Spring Data documentation.
I'm trying to implement a repository extension as described in: http://docs.spring.io/spring-data/data-neo4j/docs/3.0.2.RELEASE/reference/html/programming-model.html#d0e2970.
The code is really simple. I just have a repository and an extension interface (and implementation).
First a repository for MyType
class:
public interface MyTypeRepository extends
GraphRepository<MyType>, MyTypeRepositoryExtension { }
Then the extension interface:
public interface MyTypeRepositoryExtension {
void anyMethodNameForQuery();
}
And its implementation:
public class MyTypeRepositoryExtensionImpl {
public void anyMethodNameForQuery() {
//custom query code
}
}
With this code, Spring Data throws an error while bootstrapping its mapping infrastructure:
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property any found for type MyType!
As what I'm understanding from this error, any method that is added to the extension interface Spring Data tries to map to a property of the respective type. But that is the only use of repository extensions? That is not what I was understanding from the documentation (linked above). If that is true what are the alternatives for custom queries?
A final observation is that I'm aware of @Query
annotation, but my use case require a specific traversal and dynamic query composition.
EDIT: FURTHER INFORMATION
Looking at the documentation again I found some information that might be related to this. In order to configure repository composition it is necessary to change repository scan path from org.example.repository
to org.springframework.data.neo4j
. That is why any method that I put in the MyTypeRepositoryExtension
interface Spring Data was trying to map to a MyType
property.
I've set Spring Data Neo4j repository scan path as documented, but I've got many runtime class not found errors such as: java.io.FileNotFoundException: class path resource [javax/enterprise/inject/spi/Extension.class] cannot be opened because it does not exist"
.
In a try-and-error-totally-adhoc manner I have managed to find some dependencies that could fill out the missing classes. I've ended up with these dependencies:
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-core</artifactId>
<version>3.3.3</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-lucene4</artifactId>
<version>3.3.3</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>3.3.3</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-SP1</version>
</dependency>
That eliminated the class not found errors, but now, since I changed the repository path, Spring is not able to inject the repositories.
The documentation tries to say something about this I think, but I couldn't understand what "put it behind" means in the phrase (from the documentation): "If you use <context:component-scan>
in your spring config, please make sure to put it behind <neo4j:repositories>
, as the RepositoryFactoryBean adds new bean definitions for all the declared repositories, the context scan doesn't pick them up otherwise".
To sum up I really need some orientation here :-) ... Also, I think that the documentation needs to define the needed dependencies. And describe how extension repositories and standard repositories (interface only) can be mixed in a project.