Hibernate Search still guessing after being told which bridge


I have an abstract ancestor class for the comment table which has a trinary key. The key is in the CommentId class which is marked as @Embeddable. The three fields of the key are a long, enum, and a date. Each field of CommentId has its own @Field annotation explicitly referencing the LongBridge, EnumBridge, and DateBridge classes. Then in the Comment class, the getId() method is marked as @EmbeddedId. In the descendants the getId() method (overridden from the ancestor) is further annotated with @FieldBridge to the custom class I wrote to handle all three. (Because apparently the Search related annotations cannot be put on an abstract class.)

My custom CommentIdFieldBridge implements TwoWayFieldBridge class was built per various examples (not sure if it works or not).

No matter what I do, I still get this error during deployment:

Caused by: org.hibernate.search.exception.SearchException: HSEARCH000135: Unable to guess FieldBridge for id in gov.texas.dps.dld.dls.db.domain.dls.CommentId
	at org.hibernate.search.bridge.impl.BridgeFactory.buildFieldBridge(BridgeFactory.java:283)
	at org.hibernate.search.bridge.impl.BridgeFactory.buildFieldBridge(BridgeFactory.java:185)
	at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.createIdPropertyMetadata(AnnotationMetadataProvider.java:359)
	at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.checkDocumentId(AnnotationMetadataProvider.java:258)
	at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeMemberLevelAnnotations(AnnotationMetadataProvider.java:1062)
	at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass(AnnotationMetadataProvider.java:599)
	at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.doGetTypeMetadataFor(AnnotationMetadataProvider.java:192)
	at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor(AnnotationMetadataProvider.java:181)
	at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor(AnnotationMetadataProvider.java:165)
	at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:445)


Because apparently the Search related annotations cannot be put on an abstract class

They can.

No matter what I do, I still get this error during deployment

Make sure to put the @FieldBridge annotation in the exact same place as your @EmbeddedId annotation: getter or field. Do not put one annotation on the getter and the other on the field.

If that doesn’t solve your problem, please give us your exact code, including everything related to IDs, with all the classes involved.



Thanks for answering so fast. Well, I put the Indexed and FieldBridge annotations back onto the abstract Comment class and removed them from the descendants. I am back to where I started. The app deploys, no index directories are created and I have 8 of the following messages even though there are 15 descendants.

09:57:11,311 WARN [org.hibernate.search.spi.SearchIntegratorBuilder] (MSC service thread 1-6) HSEARCH000044: Abstract classes cannot be indexed directly. Only concrete subclasses can be indexed. Indexed on 'db.domain.dls.Comment' is superfluous and should be removed.

@DiscriminatorColumn(name = "CMTS_COMMENT_TYP", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorOptions(force = true, insert = false)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(schema = "DLNDLF", name = "COMMENT_INFO")
	@AttributeOverride(name = "userId", column = @Column(name = "CMTS_USER_ID", 
		insertable = true, nullable = false, updatable = true, length = FIELD_LEN_MAX_USER_ID)),
	@AttributeOverride(name = "userFunction", column = @Column(name = "CMTS_LST_BSN_FUNC", 
		insertable = true, nullable = false, updatable = true, length = FIELD_LEN_MAX_LAST_BUS_FUNC)) 
public abstract class Comment extends BaseDLSDataEntity<CommentId> implements Serializable {
	@FieldBridge(impl = gov.texas.dps.dld.dls.db.search.bridge.CommentIdFieldBridge.class)
	@NotNull(message = "comment.id.required")
	public CommentId getId() {
	@Column(name = "CMTS_COMMENTS", insertable = true, nullable = false, updatable = true, length = FIELD_LEN_MAX_COMMENT)
	@Field(analyze = Analyze.YES, index = Index.YES, store = Store.NO)
	@Length(max = FIELD_LEN_MAX_COMMENT, message = "comment.comment.validLength")
	@NotNull(message = "comment.comment.required")
	public String getComment() {
public class CommentId implements Serializable 
	private static final long serialVersionUID = 1L;
	public static final int FIELD_LEN_MAX_COMMENT_TYPE = 2;
	private Long commentId; // decimal(17), not null, related object's id
	private CommentTypeEnum commentTypeEnum; // char(2), not null, see discriminator
	private Timestamp recordDate; // timestamp, not null
	@Column(name = "CMTS_COMMENT_ID", insertable = true, nullable = false, updatable = false)
	@Field(analyze = Analyze.NO, index = Index.YES, bridge = FieldBridge(impl = LongBridge.class))
	@NotNull(message = "comment.id.commentId.required")
	public Long getCommentId() {
	@Column(name = "CMTS_COMMENT_TYP", insertable = false, nullable = false, updatable = false, length = FIELD_LEN_MAX_COMMENT_TYPE)
	@Field(analyze = Analyze.NO, index = Index.YES, bridge = FieldBridge(impl = EnumBridge.class)) 
	@Type(type = "db.domain.dls.type.CommentTypeEnumType")
	@NotNull(message = "comment.id.commentTypeEnum.required")
	public CommentTypeEnum getCommentTypeEnum() {
	@Column(name = "CMTS_COMMENT_DTE", insertable = true, nullable = false, updatable = false)
	@Field(analyze = Analyze.NO, index = Index.YES, bridge = FieldBridge(impl = DateBridge.class)) 
	@DateBridge(resolution = Resolution.MILLISECOND)
	@NotNull(message = "comment.id.recordDate.required")
	public Timestamp getRecordDate() {

in a descendant:

@DiscriminatorValue("AS") // see: CommentTypeEnum.ADMIN_STATUS.getValue())
public class AdministrativeStatusComment extends Comment implements Serializable {


Thanks for the answer, but please leave the code as is, do not remove the @ sign, it’s really hard to read.

You have a </> button in the text editor to tell Discourse to escape code and format it correctly. Please use that instead of blockquotes.

Alternatively, you can put your code between two lines containing just ``` (three backticks). It’s just markdown syntax.



Corrected. Sorry about that, new to this editor.



As the warning message states, @Indexed is useless on abstract classes.

What happens if you remove the @Indexed annotation from the abstract class, and move it to the concrete subclasses, without changing the other annotations? Which error do you get then?