0

我有两个表 CatalogueBase 和 CatalogueCopydetails 现在我正在使用 Hibernate 搜索 CatalogueBase 表,但我什至想在 CatalogueCopydetails 表中进行搜索。这两个表与 @ManyToOne 相关(即 CatalogueCopydetails 使用 CatalogueBase id 作为外键),听到 CatalogueBase 的一个条目,它们将是“n”个 CatalogueCopydetails

目录基础 POJO 类

@Indexed
@JsonAutoDetect
@Entity
@Table(name="catalogueBase")
public class CatalogueBase extends BaseObject implements Serializable {

    private Long id;
    ......

    @Id
    @GeneratedValue
    @Column(name="id")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    public Long getId() {
        return id;
    }

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

目录复制详细信息 POJO 类

@JsonAutoDetect
@Entity
@Table(name="cataloguecopydetails")
public class CatalogueCopyDetails extends BaseObject implements Serializable {  

    private CatalogueBase catalogueBase;
    ......
    @ManyToOne
    @JoinColumn(name="cataloguebaseid" , insertable=true, updatable=true,nullable=true)
    public CatalogueBase getCatalogueBase() {
        return catalogueBase;
    }
    public void setCatalogueBase(CatalogueBase catalogueBase) {
        this.catalogueBase = catalogueBase;
    }

    ......

至少我如何在这种情况下使用@IndexedEmbedded(我认为我不能使用@IndexedEmbedded,因为 CatalogueBase 与 CatalogueCopyDetails 没有关系,例如 OneToOne 或 OneToMany 等,只有 CatalogueCopyDetails 引用 CatalogueBase )

我怎么能这样做..?,任何帮助将不胜感激,谢谢。

4

1 回答 1

0

The easiest way would of course be to make the relation bidirectional. Is there a good reason why you don't want to do that? The other thing you could do is to add @Indexed to CatalogueCopyDetails as well and use @IndexedEmbedded on CatalogueBase. You could then write a query using the CatalogueCopyDetails index. Whether this works will depend on your use case and what you actually want as result of query.

于 2013-09-04T21:18:10.993 回答