一个星期以来我一直在努力解决这个问题,但似乎仍然找不到解决方案。我正在使用 spring-data-neo4j maven artifact 和以下导致此问题的代码行:
/**
*
*/
@Autowired
private UserRepository userRepository;
@Transactional
public void addClassDescriptor(User user, ClassDescriptor classDescriptor) {
Project project = user.getDefaultProject();
ManagedFieldAccessorSet<ClassDescriptor> accessorSet = (ManagedFieldAccessorSet<ClassDescriptor>) project.getClassDescriptors();
accessorSet.add(classDescriptor);
/*
* Save the user object after updating the set
*/
userRepository.save(user);
}
执行该方法时,会出现以下错误
accessorSet.add(classDescriptor);
堆栈跟踪:
org.neo4j.graphdb.NotInTransactionException
at org.neo4j.kernel.impl.persistence.PersistenceManager.getResource(PersistenceManager.java:252)
at org.neo4j.kernel.impl.persistence.PersistenceManager.nodeCreate(PersistenceManager.java:155)
at org.neo4j.kernel.impl.core.NodeManager.createNode(NodeManager.java:270)
at org.neo4j.kernel.EmbeddedGraphDbImpl.createNode(EmbeddedGraphDbImpl.java:317)
at org.neo4j.kernel.EmbeddedGraphDatabase.createNode(EmbeddedGraphDatabase.java:103)
at org.springframework.data.neo4j.support.DelegatingGraphDatabase.createNode(DelegatingGraphDatabase.java:82)
at org.springframework.data.neo4j.support.mapping.EntityStateHandler.useOrCreateState(EntityStateHandler.java:115)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.write(Neo4jEntityConverterImpl.java:145)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.write(Neo4jEntityPersister.java:176)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:238)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:227)
at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:295)
at org.springframework.data.neo4j.fieldaccess.AbstractNodeRelationshipFieldAccessor.getOrCreateState(AbstractNodeRelationshipFieldAccessor.java:97)
at org.springframework.data.neo4j.fieldaccess.AbstractNodeRelationshipFieldAccessor.createSetOfTargetNodes(AbstractNodeRelationshipFieldAccessor.java:89)
at org.springframework.data.neo4j.fieldaccess.OneToNRelationshipFieldAccessorFactory$OneToNRelationshipFieldAccessor.setValue(OneToNRelationshipFieldAccessorFactory.java:66)
at org.springframework.data.neo4j.fieldaccess.ManagedFieldAccessorSet.updateValue(ManagedFieldAccessorSet.java:90)
at org.springframework.data.neo4j.fieldaccess.ManagedFieldAccessorSet.update(ManagedFieldAccessorSet.java:78)
at org.springframework.data.neo4j.fieldaccess.ManagedFieldAccessorSet.add(ManagedFieldAccessorSet.java:104)
我的实体如下:(User.java)
@GraphId
private Long id;
@RelatedTo(elementClass = Project.class)
@Fetch
private Set<Project> projects;
(项目.java)
@GraphId
private Long id;
/**
*
*/
@RelatedTo(elementClass = ClassDescriptor.class)
@Fetch
private Set<ClassDescriptor> classDescriptors;
/**
*
*/
private boolean defaultProject;
请帮忙 !附件是依赖树。