给定以下两个对象:
@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);
}