有多个属性针对相同的字段名称索引,但具有不同的索引设置。行为未定义

时间:2014-06-23 19:19:20

标签: java hibernate hibernate-search

运行Hibernate Search应用程序时,在我的日志中获取以下内容:

WARN 23 Jun 2014 15:08:51,623 org.hibernate.search.engine.metadata.impl.TypeMetadata:339 - HSEARCH000120: There are multiple properties indexed against the same field name 'foo.bar', but with different indexing settings. The behaviour is undefined.

我看到警告正在记录:

private Map<String, DocumentFieldMetadata> keyFieldMetadata(Set<PropertyMetadata> propertyMetadataSet) {
    Map<String, DocumentFieldMetadata> tmpMap = new HashMap<String, DocumentFieldMetadata>();
    for ( PropertyMetadata propertyMetadata : propertyMetadataSet ) {
        for ( DocumentFieldMetadata documentFieldMetadata : propertyMetadata.getFieldMetadata() ) {
            DocumentFieldMetadata oldFieldMetadata = tmpMap.put(
                    documentFieldMetadata.getName(),
                    documentFieldMetadata
            );
            if ( oldFieldMetadata != null ) {
                if ( !documentFieldMetadata.getIndex().equals( oldFieldMetadata.getIndex() ) ) {
                    **log.inconsistentFieldConfiguration( documentFieldMetadata.getName()** );
                }
            }
        }
    }

    for ( DocumentFieldMetadata documentFieldMetadata : classBridgeFields ) {
        tmpMap.put( documentFieldMetadata.getName(), documentFieldMetadata );
    }

    if ( idPropertyMetadata != null ) {
        for ( DocumentFieldMetadata documentFieldMetadata : idPropertyMetadata.getFieldMetadata() ) {
            tmpMap.put( documentFieldMetadata.getName(), documentFieldMetadata );
        }
    }
    return Collections.unmodifiableMap( tmpMap );
}

但是我无法弄清楚这段代码的用途,或者我的代码如何导致它满足条件。它似乎只发生在使用@IndexedEmbedded注释的字段上进行了Google搜索,但没有找到错误。

我认为这一直是代码中的一个问题,但我最近刚从Hibernate Search 4.2.0.Final更新到4.5.1.Final,这就是警告开始出现的时候。

更新

@Entity
@Table(name = "data_providers")
@Immutable
@Embeddable
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class EDataProvider {

   private static final long serialVersionUID = -4207808146855081627L;

   public static final String FIELD_ASSOCIATIONS = "associations.";

   public static final String FIELD_ID = "id";

   private List<EDataProvider> associatedProviders;

   private Long id;

   private boolean isInternal;

   private String name;

   private Float priority;

   public EDataProvider() {

      this(null, null);
   }

   /**
    * @param name
    * @param id
    */
   public EDataProvider(final String name, final Long id) {

      super();
      this.name = name;
      this.id = id;
      associatedProviders = new Vector<EDataProvider>();
   }

   /**
    * @param newProvider
    */
   public void addAssociatedProvider(final EDataProvider newProvider) {

      associatedProviders.add(newProvider);
   }

   @Override
   public boolean equals(final Object obj) {

      if (this == obj) {
         return true;
      }
      if ((obj == null) || !(obj instanceof EDataProvider)) {
         return false;
      }
      final EDataProvider other = (EDataProvider) obj;
      if (!ObjectUtil.equals(getId(), other.getId())) {
         return false;
      }
      return true;
   }

   @ManyToMany(fetch = FetchType.LAZY,
               cascade = { CascadeType.PERSIST, CascadeType.MERGE })
   @JoinTable(name = "data_provider_associations",
              joinColumns = { @JoinColumn(name = "parent_id") },
              inverseJoinColumns = { @JoinColumn(name = "child_id") })
   @IndexedEmbedded(depth = 1,
                    prefix = FIELD_ASSOCIATIONS)
   @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
   public List<EDataProvider> getAssociatedProviders() {

      return associatedProviders;
   }

   @Id
   @Column(name = "id")
   @Field(name = FIELD_ID)
   public Long getId() {

      return id;
   }

   @Column(name = "name")
   public String getName() {

      return name;
   }

   @Column(name = "boost")
   public Float getPriority() {

      return priority;
   }

   @Override
   public int hashCode() {

      return EncodingUtil.makeHashCode(31, getId());
   }

   @Column(name = "internal")
   public boolean isInternal() {

      return isInternal;
   }

   public void removeAssociatedProvider(final EDataProvider newProvider) {

      associatedProviders.remove(newProvider);
   }

   /**
    * @param newAssociatedProviders
    *           the associatedProviders to set
    */
   public void setAssociatedProviders(
         final List<EDataProvider> newAssociatedProviders) {

      associatedProviders = newAssociatedProviders;
   }

   /**
    * @param dataProviderId
    *           the dataProviderId to set
    */
   public void setId(final Long dataProviderId) {

      id = dataProviderId;
   }

   public void setInternal(final boolean isInternal) {

      this.isInternal = isInternal;
   }

   /**
    * @param name
    *           the name to set
    */
   public void setName(final String name) {

      this.name = name;
   }

   /**
    * @param priority
    *           the priority to set
    */
   public void setPriority(final Float priority) {

      this.priority = priority;
   }

   @Override
   public String toString() {

      return String.format("provider:{id:%d, name:%s, priority:%f}", id, name,
            priority);
   }
}

1 个答案:

答案 0 :(得分:0)

ID字段在子对象中使用@Field注释进行注释,并包含在父对象的索引中。父对象使用自定义分析器,因此索引设置中存在冲突。一旦我从子对象中删除了@Field注释,错误便消失了。