简体   繁体   English

更新子选择实体的索引

[英]updating an index on an subselect entity

In my project, I have entities that I cannot change, but I need to create an index on top one of them.在我的项目中,我有一些无法更改的实体,但我需要在其中一个实体之上创建一个索引。 That an example what I want to archive:这是我要存档的示例:

That is the entities that I cannot change:那是我无法更改的实体:

@Entity
@Table(name = "main")
public class FirstEntity {

    @Id
    private Long id;

    @ManyToOne
    private SecondEntity secondaryEntity;
}

@Entity
@Table(name = "secondary")
public class SecondEntity {

    @Id
    private Long id;
    
    private String name;

}

My entity我的实体

@Indexed
@Entity
@Subselect("select * from main")
//@Table(name = "main")
//@Immutable
public class ThirdEntity {
    @Id
    private Long id;

    @ManyToOne
    private SecondEntity secondaryEntity;

    @Transient
    @GenericField(sortable = Sortable.YES)
    @IndexingDependency(derivedFrom = {
            @ObjectPath(@PropertyValue(propertyName = "secondaryEntity"))
    })
    public String getName() {
        return secondaryEntity.getName();
    }
}

Whenever the SecondEntity changes, the index for ThirdEntity remains the same.每当 SecondEntity 更改时,ThirdEntity 的索引保持不变。

I wrote a small/simple example https://github.com/YaroslavTir/reindex-subselect-entity我写了一个小/简单的例子https://github.com/YaroslavTir/reindex-subselect-entity

I have in mind a workaround solution.我想到了一个解决方法。 Using hibernateListeners and rebuild index for ThirdEntity by hand, but that is not really nice solution.使用 hibernateListeners 并手动为 ThirdEntity 重建索引,但这并不是很好的解决方案。

Your indexing dependency annotation is incomplete, it should be something like:你的索引依赖注解不完整,应该是这样的:

   @IndexingDependency(derivedFrom = {
        @ObjectPath(
            @PropertyValue(propertyName = "secondaryEntity"),
            @PropertyValue(propertyName = "name")
        )
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM