2015-04-06 17 views
0

我試圖刪除node_auto_indexing中的字段。 當我嘗試使用repository.delete(id)刪除節點。 緊接着,我試圖通過它的ID來獲得刪除節點,我得到以下異常:嵌入式Neo4j刪除節點和Lucene傳統索引 - node_auto_indexing不同步問題

java.lang.IllegalStateException: This index (Index[__rel_types__,Relationship]) has been marked as deleted in this transaction 
    at org.neo4j.index.impl.lucene.LuceneTransaction$DeletedTxDataBoth.illegalStateException(LuceneTransaction.java:475) 
    at org.neo4j.index.impl.lucene.LuceneTransaction$DeletedTxDataBoth.removed(LuceneTransaction.java:470) 
    at org.neo4j.index.impl.lucene.LuceneTransaction.remove(LuceneTransaction.java:112) 
    at org.neo4j.index.impl.lucene.LuceneXaConnection.remove(LuceneXaConnection.java:116) 
    at org.neo4j.index.impl.lucene.LuceneIndex.remove(LuceneIndex.java:215) 
    at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexBasedTypeRepresentationStrategy.remove(AbstractIndexBasedTypeRepresentationStrategy.java:113) 
    at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexBasedTypeRepresentationStrategy.preEntityRemoval(AbstractIndexBasedTypeRepresentationStrategy.java:100) 
    at org.springframework.data.neo4j.support.mapping.EntityRemover.removeRelationship(EntityRemover.java:63) 
    at org.springframework.data.neo4j.support.mapping.EntityRemover.removeNode(EntityRemover.java:51) 
    at org.springframework.data.neo4j.support.mapping.EntityRemover.removeNodeEntity(EntityRemover.java:45) 
    at org.springframework.data.neo4j.support.mapping.EntityRemover.remove(EntityRemover.java:85) 
    at org.springframework.data.neo4j.support.Neo4jTemplate.delete(Neo4jTemplate.java:267) 
    at org.springframework.data.neo4j.repository.AbstractGraphRepository.delete(AbstractGraphRepository.java:276) 
    at org.springframework.data.neo4j.repository.AbstractGraphRepository.delete(AbstractGraphRepository.java:282) 

此外,當我試圖通過暗號查詢

@Query("MATCH()-[r]-(p:Product) WHERE id(p) = {productId} DELETE r, p") 
void deleteProduct(@Param("productId") Long productId); 

我刪除節點m到處另一個異常通過其ID尋找這個刪除節點後:

java.lang.IllegalStateException: No primary SDN label exists .. (i.e one starting with _) 
    at org.springframework.data.neo4j.support.typerepresentation.LabelBasedNodeTypeRepresentationStrategy.readAliasFrom(LabelBasedNodeTypeRepresentationStrategy.java:126) 
    at org.springframework.data.neo4j.support.typerepresentation.LabelBasedNodeTypeRepresentationStrategy.readAliasFrom(LabelBasedNodeTypeRepresentationStrategy.java:39) 
    at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasFrom(TRSTypeAliasAccessor.java:36) 
    at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasFrom(TRSTypeAliasAccessor.java:26) 
    at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:102) 
    at org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeUsed(DefaultTypeMapper.java:165) 
    at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:142) 
    at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.read(Neo4jEntityConverterImpl.java:78) 
    at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.read(Neo4jEntityPersister.java:170) 
    at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createEntityFromState(Neo4jEntityPersister.java:189) 
    at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState(Neo4jTemplate.java:224) 
    at org.springframework.data.neo4j.repository.AbstractGraphRepository.createEntity(AbstractGraphRepository.java:62) 
    at org.springframework.data.neo4j.repository.AbstractGraphRepository.findOne(AbstractGraphRepository.java:127) 
    at org.springframework.data.neo4j.repository.AbstractGraphRepository.delete(AbstractGraphRepository.java:282) 

如何正確刪除,在Lucene的舊索引node_auto_indexing參與的節點?如何從Lucene索引中刪除此節點?

更新:

這是我Neo4jConfig

@Configuration 
@EnableNeo4jRepositories(basePackages = "com.example") 
@EnableTransactionManagement 
public class Neo4jConfig extends Neo4jConfiguration implements BeanFactoryAware { 

    @Resource 
    private Environment environment; 

    private BeanFactory beanFactory; 

    public Neo4jConfig() { 
     setBasePackage("com.example"); 
    } 

    @Bean(destroyMethod = "shutdown") 
    public GraphDatabaseService graphDatabaseService() { 

     GraphDatabaseService graphDb = new GraphDatabaseFactory() 
       .newEmbeddedDatabaseBuilder("target/example-test-db") 
       .setConfig(GraphDatabaseSettings.node_keys_indexable, "name,description") 
       .setConfig(GraphDatabaseSettings.node_auto_indexing, "true") 
       .newGraphDatabase(); 

     return graphDb; 
    } 

    /** 
    * Hook into the application lifecycle and register listeners that perform 
    * behaviour across types of entities during this life cycle 
    * 
    */ 
    @Bean 
    protected ApplicationListener<BeforeSaveEvent<BaseEntity>> beforeSaveEventApplicationListener() { 
     return new ApplicationListener<BeforeSaveEvent<BaseEntity>>() { 
      @Override 
      public void onApplicationEvent(BeforeSaveEvent<BaseEntity> event) { 
       BaseEntity entity = event.getEntity(); 
       if (entity.getCreateDate() == null) { 
        entity.setCreateDate(new Date()); 
       } else { 
        entity.setUpdateDate(new Date()); 
       } 
      } 
     }; 
    } 

    @Override 
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException { 
     this.beanFactory = beanFactory; 
    } 

    public BeanFactory getBeanFactory() { 
     return beanFactory; 
    } 

} 

在項目單位基本單位:

public class BaseEntity { 

    private Date createDate; 

    private Date updateDate; 

    public BaseEntity() { 
    } 

    public Date getCreateDate() { 
     return createDate; 
    } 

    public void setCreateDate(Date createDate) { 
     this.createDate = createDate; 
    } 

    public Date getUpdateDate() { 
     return updateDate; 
    } 

    public void setUpdateDate(Date updateDate) { 
     this.updateDate = updateDate; 
    } 

} 

Vote實體,我試圖刪除:

@NodeEntity 
public class Vote extends BaseEntity { 

    private static final String VOTED_ON = "VOTED_ON"; 
    private final static String VOTED_FOR = "VOTED_FOR"; 
    private static final String CREATED_BY = "CREATED_BY"; 

    @GraphId 
    private Long id; 

    @RelatedTo(type = VOTED_FOR, direction = Direction.OUTGOING) 
    private Decision decision; 

    @RelatedTo(type = VOTED_ON, direction = Direction.OUTGOING) 
    private Criterion criterion; 

    @RelatedTo(type = CREATED_BY, direction = Direction.OUTGOING) 
    private User author; 

    private double weight; 

    private String description; 

    public Vote() { 
    } 

    public Vote(Decision decision, Criterion criterion, User author, double weight, String description) { 
     this.decision = decision; 
     this.criterion = criterion; 
     this.author = author; 
     this.weight = weight; 
     this.description = description; 
    } 

    public Long getId() { 
     return id; 
    } 

    public void setId(Long id) { 
     this.id = id; 
    } 

    public Decision getDecision() { 
     return decision; 
    } 

    public void setDecision(Decision decision) { 
     this.decision = decision; 
    } 

    public Criterion getCriterion() { 
     return criterion; 
    } 

    public void setCriterion(Criterion criterion) { 
     this.criterion = criterion; 
    } 

    public User getAuthor() { 
     return author; 
    } 

    public void setAuthor(User author) { 
     this.author = author; 
    } 

    public double getWeight() { 
     return weight; 
    } 

    public void setWeight(double weight) { 
     this.weight = weight; 
    } 

    public String getDescription() { 
     return description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 

    @Override 
    public boolean equals(Object o) { 
     if (this == o) 
      return true; 
     if (o == null || getClass() != o.getClass()) 
      return false; 
     Vote vote = (Vote) o; 
     if (id == null) 
      return super.equals(o); 
     return id.equals(vote.id); 
    } 

    @Override 
    public int hashCode() { 
     return id != null ? id.hashCode() : super.hashCode(); 
    } 

    @Override 
    public String toString() { 
     return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); 
    } 

} 
+0

也許你可以分享你如何集成auto_index中,你的實體是什麼樣子?我不明白「__rel_types__」索引如何被標記爲刪除。最好提供一個重現問題的GitHub項目。 –

+0

@MichaelHunger謝謝你的回答。我更新了問題主體。如果這些信息沒有幫助,我會考慮如何創建一個重現問題的例子。 – alexanoid

回答

0

感謝@MichaelHunger和Neo4j的這個問題已被固定在Neo4j的2.2.2和SDN 3.4.0.M1