次の 2 つのオブジェクトがあるとします。
@NodeEntity
class Foo
{
@GraphId
long id;
@RelatedTo(Bar.class,direction=Direction.BOTH, type="BAR")
Set<Bar> bars= new HashSet<Bar>();
@Indexed
String name;
}
と
@NodeEntity
class Bar
{
@GraphId
long id;
@RelatedTo(Foo.class,direction=Direction.BOTH, type="Foo")
Set<Foo> foos= new HashSet<Foo>();
@Indexed
String name;
}
次の永続性レベルのコードは非常に遅いです (永続化が遅いごとに 5 ~ 20 秒)。
@Service
class Persister
{
@Autowired
Neo4JTemplate template;
@Autowired
FooRepository fooRepo;
@Autowired
BarRepository barRepo;
void go()
{
Bar bar = barRepo.findByName("myBar");
if(null != bar)
{
bar.getFoos().addAll(fooRepo.readAll());
return bar;
}
template.save(bar);
}
}
interface BarRepository extends Repository<Bar>
{
Bar findByName(String name);
}