diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/graph/annotation/GraphQuery.java b/spring-data-neo4j/src/main/java/org/springframework/data/graph/annotation/GraphQuery.java
new file mode 100644
index 000000000..eab560ab5
--- /dev/null
+++ b/spring-data-neo4j/src/main/java/org/springframework/data/graph/annotation/GraphQuery.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.data.graph.annotation;
+
+import org.springframework.data.graph.core.FieldTraversalDescriptionBuilder;
+import org.springframework.data.graph.core.NodeBacked;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Field that provides access to an iterator which is created by applying the traversal that is built by the supplied
+ * traversal builder to the current node. The result elements are automatically converted to appropriate element
+ * entity class instances.
+ *
+ * @GraphTraversal(traversalBuilder=FriendTraversalBuilder.class, elementClass=Person.class)
+ * Iterable<Person> friends;
+ *
+ * @author Michael Hunger
+ * @since 15.09.2010
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface GraphQuery {
+ /**
+ * @return Query to be executed %d will be replaced by the node-id of the current entity other placeholders by the given params
+ */
+ String value() default "";
+
+ /**
+ * @return target type to convert the single result column (if any) to.
+ */
+ Class> elementClass() default Object.class;
+
+ /**
+ * @return parameters that are replaced in the to the @see query-string
+ */
+ String[] params() default {};
+}
diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/fieldaccess/QueryFieldAccessorFactory.java b/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/fieldaccess/QueryFieldAccessorFactory.java
new file mode 100644
index 000000000..4d88d1aff
--- /dev/null
+++ b/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/fieldaccess/QueryFieldAccessorFactory.java
@@ -0,0 +1,100 @@
+/**
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.data.graph.neo4j.fieldaccess;
+
+import org.neo4j.graphdb.traversal.TraversalDescription;
+import org.springframework.dao.InvalidDataAccessApiUsageException;
+import org.springframework.data.graph.annotation.GraphQuery;
+import org.springframework.data.graph.annotation.GraphTraversal;
+import org.springframework.data.graph.core.FieldTraversalDescriptionBuilder;
+import org.springframework.data.graph.core.NodeBacked;
+import org.springframework.data.graph.neo4j.support.node.Neo4jNodeBacking;
+import org.springframework.data.graph.neo4j.support.query.QueryExecutor;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+
+import static org.springframework.data.graph.neo4j.support.DoReturn.doReturn;
+
+public class QueryFieldAccessorFactory implements FieldAccessorFactory {
+ @Override
+ public boolean accept(final Field f) {
+ final GraphQuery graphQuery = f.getAnnotation(GraphQuery.class);
+ return graphQuery != null
+ && !graphQuery.value().isEmpty();
+ }
+
+
+ @Override
+ public FieldAccessor forField(final Field field) {
+ return new QueryFieldAccessor(field);
+ }
+
+ /**
+ * @author Michael Hunger
+ * @since 12.09.2010
+ */
+ public static class QueryFieldAccessor implements FieldAccessor {
+ protected final Field field;
+ private final String query;
+ private Class> target;
+ protected String[] params;
+ private boolean iterableResult;
+
+ public QueryFieldAccessor(final Field field) {
+ this.field = field;
+ final GraphQuery graphQuery = field.getAnnotation(GraphQuery.class);
+ this.target = graphQuery.elementClass();
+ this.params = graphQuery.params();
+ this.query = graphQuery.value();
+ this.iterableResult = Iterable.class.isAssignableFrom(field.getType());
+ }
+
+ @Override
+ public boolean isWriteable(NodeBacked nodeBacked) {
+ return false;
+ }
+
+ @Override
+ public Object setValue(final NodeBacked nodeBacked, final Object newVal) {
+ throw new InvalidDataAccessApiUsageException("Cannot set readonly query field " + field);
+ }
+
+ @Override
+ public Object getValue(final NodeBacked nodeBacked) {
+ final String queryString = String.format(this.query, createPlaceholderParams(nodeBacked));
+ return doReturn(executeQuery(nodeBacked, queryString));
+ }
+
+ private Object executeQuery(NodeBacked nodeBacked, String queryString) {
+ if (iterableResult) {
+ if (target.equals(Object.class)) return nodeBacked.findAllByQuery(queryString);
+ nodeBacked.findAllByQuery(queryString, this.target);
+ }
+ return nodeBacked.findByQuery(query,this.target);
+ }
+
+ private Object[] createPlaceholderParams(NodeBacked nodeBacked) {
+ if (params.length==0) return new Object[] {nodeBacked.getNodeId()};
+
+ final Object[] parameters = new Object[1 + this.params.length];
+ parameters[0]=nodeBacked.getNodeId();
+ System.arraycopy(this.params,0,parameters,1,this.params.length);
+ return parameters;
+ }
+ }
+}
diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/support/node/Neo4jNodeBacking.aj b/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/support/node/Neo4jNodeBacking.aj
index 13835707b..8c2f6d507 100644
--- a/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/support/node/Neo4jNodeBacking.aj
+++ b/spring-data-neo4j/src/main/java/org/springframework/data/graph/neo4j/support/node/Neo4jNodeBacking.aj
@@ -37,8 +37,10 @@ import javax.persistence.Transient;
import javax.persistence.Entity;
import org.springframework.data.graph.neo4j.support.path.EntityPathPathIterableWrapper;
+import org.springframework.data.graph.neo4j.support.query.QueryExecutor;
import java.lang.reflect.Field;
+import java.util.Map;
import static org.springframework.data.graph.neo4j.support.DoReturn.unwrap;
@@ -173,6 +175,20 @@ public aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMixinFields(traverser, targetType, Neo4jNodeBacking.aspectOf().graphDatabaseContext);
}
+ public Iterable NodeBacked.findAllByQuery(final String query, final Class targetType) {
+ final QueryExecutor executor = new QueryExecutor(Neo4jNodeBacking.aspectOf().graphDatabaseContext);
+ return executor.query(query, targetType);
+ }
+
+ public Iterable