Lucene Indexes for DB View

Hello,
i have a view in my Postgre database and i create an entity view.

My entity view has 2 primary keys.

@Immutable
@IdClass(ViewId.class)
@Indexed(index = "idx")
@Table(name = "view")
public class View {
	
	@Id
	@DocumentId
	@Column(name = "pk1", precision = 18)
	private BigInteger pk1;
	
	@Id
	@DocumentId
	@Column(name = "pk2", precision = 2)
	private BigDecimal pk2;

    @Column(name = "descr", length = 100)
	@GenericField(sortable = Sortable.YES)
	private String descr;
}
  1. @DocumentId is necessary?
  2. Is it possible to create Lucene Indexes on my View Entity, to use @Indexed, @GenericField etc

Thank you !

Hey Tony,

Thanks for reaching out. See the answers below:

Absolutely :smiley:. This is actually a case when explicit ID mapping is required. See this section of the documentation for more details - Hibernate Search 6.2.2.Final: Reference Documentation . If the suggestions in the docs won’t fit your needs you could also try to add something like:

@DocumentId
public String getDocumentID() {
	return id1 + "-" + id2;
}

public void setDocumentID(String ignored) {
	// do nothing
}

to your entity to generate that document ID. Alternatively, if you’d switch to @EmbeddedId you’d need to go the identifier bridge route: Hibernate Search 6.2.2.Final: Reference Documentation

Since it is a view, you will not be making updates to it via Hibernate ORM directly, meaning you will not modify View instance values and then persist it. That means that you won’t get the index updated when the view changes on the database side. But you should still be able to populate the index with massindexer or by manually building an indexing plan