[英]neo4j template slow persistence when dealing with bidirectional relationships
Given the following two objects: 给定以下两个对象:
@NodeEntity
class Foo
{
@GraphId
long id;
@RelatedTo(Bar.class,direction=Direction.BOTH, type="BAR")
Set<Bar> bars= new HashSet<Bar>();
@Indexed
String name;
}
and 和
@NodeEntity
class Bar
{
@GraphId
long id;
@RelatedTo(Foo.class,direction=Direction.BOTH, type="Foo")
Set<Foo> foos= new HashSet<Foo>();
@Indexed
String name;
}
The following persistence level code is dreadfully slow (5-20 seconds per persist slow) 以下持久性级别代码令人恐惧地缓慢(每个持久性缓慢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);
}
Are you using Neo4j REST interface? 您正在使用Neo4j REST接口吗? If so, my this post may provide a clue - Performance with @MapResult in spring-data-neo4j
如果是这样,我的这篇文章可能会提供一个线索-spring-data-neo4j中@MapResult的性能
How many foo's are you adding to bar
? 有多少Foo的要补充到
bar
?
Are you using simple mapping or advanced mapping? 您使用的是简单映射还是高级映射?
You should have a @Transactional
around your go()
method, otherwise there will be thousands of small transactions created for each entity added. 您应该在
go()
方法周围使用@Transactional
,否则为每个添加的实体创建数千个小交易。 (in advanced mode, in simple mode that code doesn't save the changes.) (在高级模式下,在简单模式下,代码不会保存更改。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.