Can Someone Please help me out? estou preso em um erro que aponta para a chave primaria composta da minha classe ao indexar as classes

ERROR 6092 — [ entityloader-1] o.h.s.exception.impl.LogErrorHandler : HSEARCH000058: HSEARCH000212: An exception occurred while the MassIndexer was transforming identifiers to Lucene Documents

java.lang.ClassCastException: class br.com.trevo.infraestructure.project.entity.ProjectSystemEntityPk cannot be cast to class java.lang.Long (br.com.trevo.infraestructure.project.entity.ProjectSystemEntityPk is in unnamed module of loader ‘app’; java.lang.Long is in module java.base of loader ‘bootstrap’)

class
@Data
@ToString(callSuper = true, of = {“id”})
@EqualsAndHashCode(callSuper = true, of = {“id”})
@EntityListeners(AuditingEntityListener.class)
@NoArgsConstructor
@MappedSuperclass
public abstract class ProjectSystemEntity extends CommonExtractorEntity {

@Transient
private static final long serialVersionUID = 1L;


@EmbeddedId
@AttributeOverrides({
        @AttributeOverride(
                name = "project",
                column = @Column(name = "project_id", insertable = false)
        ),
        @AttributeOverride(
                name = "system_id",
                column = @Column(name = "system_id", insertable = false)
        ),
        @AttributeOverride(
                name = "cid",
                column = @Column(name = "cid", columnDefinition = "bigserial", insertable = false, updatable = false, nullable = false)

        )
})
private ProjectSystemEntityPk<Long> scope;

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cid", columnDefinition = "bigserial", insertable = false, updatable = false, nullable = false)
private Long cid;

@ManyToOne
@JoinColumn(name = "system_id", insertable = false, updatable = false)
protected System system;

@Column(columnDefinition = "bigserial", insertable = false, updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)

@DocumentId
protected Long id;

I don’t think Hibernate Search 5 supports mass indexing entities whose document ID is not the entity ID.

If you’re haven’t written too much code with Hibernate Search 5 yet, I would recommend upgrading to Hibernate Search 6 (still in beta). Many problems were fixed in 6, and your use case might just work. APIs are quite different however, so you’ll have to rewrite what you have done. You’ll find a getting started guide here.

If you decide to stick with Hibernate Search 5, you can try moving @DocumentId to the entity ID and using a custom bridge. See here.

1 Like