Skip to content

Commit de0d857

Browse files
committed
GH-2201 - Add test and documentation.
Add another test to verify multi-interface support. Mention in the documentation not to use interfaces with repositories.
1 parent 2027c25 commit de0d857

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

src/main/asciidoc/object-mapping/mapping.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ The data structure needed is shown in the following test. The same would be writ
125125
include::../../../../src/test/java/org/springframework/data/neo4j/integration/imperative/InheritanceMappingIT.java[tag=interface3]
126126
----
127127

128+
NOTE: Interfaces cannot define an identifier field.
129+
As a consequence they are not a valid entity type for repositories.
130+
128131
[[mapping.annotations.node.dynamic.labels]]
129132
==== Dynamic or "runtime" managed labels
130133

src/test/java/org/springframework/data/neo4j/integration/imperative/InheritanceMappingIT.java

+21
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import org.junit.jupiter.api.BeforeEach;
1919
import org.junit.jupiter.api.Test;
2020
import org.neo4j.driver.Driver;
21+
import org.neo4j.driver.Record;
2122
import org.neo4j.driver.Session;
2223
import org.neo4j.driver.Transaction;
24+
import org.neo4j.driver.types.Node;
2325
import org.springframework.beans.factory.annotation.Autowired;
2426
import org.springframework.context.annotation.Bean;
2527
import org.springframework.context.annotation.Configuration;
@@ -303,6 +305,25 @@ void mixedImplementationsWrite(@Autowired Neo4jTemplate template) {
303305
});
304306
}
305307

308+
@Test // GH-2201
309+
void mixedInterfaces(@Autowired Neo4jTemplate template) {
310+
311+
Inheritance.Mix1AndMix2 mix1AndMix2 = new Inheritance.Mix1AndMix2("a", "b");
312+
313+
mix1AndMix2 = template.save(mix1AndMix2);
314+
315+
assertThat(mix1AndMix2.getName()).isEqualTo("a");
316+
assertThat(mix1AndMix2.getValue()).isEqualTo("b");
317+
318+
try (Session session = driver.session()) {
319+
List<Record> records = session.run("MATCH (n) RETURN n").list();
320+
assertThat(records).hasSize(1);
321+
Record record = records.get(0);
322+
Node node = record.get("n").asNode();
323+
assertThat(node.labels()).containsExactlyInAnyOrder("Mix1", "Mix2", "Mix1AndMix2");
324+
}
325+
}
326+
306327
interface PetsRepository extends Neo4jRepository<AbstractPet, Long> {
307328

308329
@Query("MATCH (n {name: $name}) RETURN n")

src/test/java/org/springframework/data/neo4j/integration/shared/common/Inheritance.java

+44
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,50 @@ public void setRelated2(SomeInterface3 related2) {
279279
}
280280
// end::interface3[]
281281

282+
/**
283+
* Interface to get implemented with the one below.
284+
*/
285+
@Node("Mix1")
286+
public interface MixIt1 {
287+
String getName();
288+
}
289+
290+
/**
291+
* Interface to get implemented with one above.
292+
*/
293+
@Node("Mix2")
294+
public interface MixIt2 {
295+
String getValue();
296+
}
297+
298+
/**
299+
* Implements two interfaces
300+
*/
301+
@Node
302+
public static class Mix1AndMix2 implements MixIt1, MixIt2 {
303+
304+
@Id
305+
@GeneratedValue
306+
private Long id;
307+
308+
private final String name;
309+
private final String value;
310+
311+
public Mix1AndMix2(String name, String value) {
312+
this.name = name;
313+
this.value = value;
314+
}
315+
316+
@Override
317+
public String getName() {
318+
return name;
319+
}
320+
321+
@Override
322+
public String getValue() {
323+
return value;
324+
}
325+
}
282326
/**
283327
* super base class
284328
*/

0 commit comments

Comments
 (0)