V
V
Vitaly Gusev2022-04-01 20:24:36
MySQL
Vitaly Gusev, 2022-04-01 20:24:36

How to index a text field in Hibernate?

If we want to index a field (column) of a table using Hibernate, we write:

@Entity
@Table(name = "page", indexes = {@Index(columnList = "path", name = "path_indx")})
public class Page {
......
@Column(name = "path", columnDefinition = "TEXT", nullable = false)
@Type( type = "org.hibernate.type.TextType")
@NotNull
String path; код

but if the field is text, to index text fields (in MySQL) you must explicitly specify the length of the indexed prefix (the number of characters from the beginning of the record on which to build the index). Can't find syntax how to specify prefix length in Hibernate for text field.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question