# Searching through enum set

**URL:** <https://discourse.hibernate.org/t/searching-through-enum-set/12194>\
**Category:** Hibernate Search\
**Created:** [March 27, 2026, 2:06pm UTC](https://discourse.hibernate.org/t/searching-through-enum-set/12194 "2026-03-27T14:06:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![horvoje](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/horvoje/32/779_2.png) [@horvoje](https://discourse.hibernate.org/u/horvoje)\
**Post date:** [March 27, 2026, 2:06pm UTC](https://discourse.hibernate.org/t/searching-through-enum-set/12194/1 "2026-03-27T14:06:32Z")

</div>

Hi! I’m trying to implement indexing against set of enums.  
(Java 21 **•** Hibernate 7.3.0.Final **•** Hibernate Search 8.3.0.Final)

```java
public enum UserRole {
    ROLE_ADMIN,
    ROLE_EDITOR...
}

```

```java
@Column( columnDefinition = "TEXT" )
@Convert( converter = UserRolesConverter.class )
//	@Enumerated(EnumType.STRING)
@PropertyBinding(
    binder = @PropertyBinderRef( type = UserRolesPropertyBinder.class )
)
private Set<UserRole> roles;

```

Enums are stored as a string rather than a collection in addtional table.

The problem is I don’t know how to add the bridge to the context.

```java
public class UserRolesPropertyBinder
        implements PropertyBinder
{

	@Override
	public void bind( final PropertyBindingContext context ) {

		context.dependencies().useRootOnly();

		final UserRolePropertyBridge userRolesBridge =
			new UserRolePropertyBridge(
				context
					.indexSchemaElement()
					.field(
                        context.bridgedElement().name(),
                        f -> f.asString()
                    )
					.toReference()
			);

//-------------------------------------------------------
		context.bridge( ??????, userRolesBridge );
//-------------------------------------------------------

	}

    private static class UserRolePropertyBridge
            implements
                    PropertyBridge<Set<UserRole>>
    {

        private final IndexFieldReference<String> stringField;

        private UserRolePropertyBridge(
            final IndexFieldReference<String> stringField
        ) {
			this.stringField = stringField;
		}

		@Override
		public void write(
            final DocumentElement target,
            final Set<UserRole> userRoles,
            final PropertyBridgeWriteContext context
        ) {
			for( final UserRole role : userRoles ) {
				target.addValue( this.stringField, role.name() );
			}
		}

	}

}

```

Tried to find solution to employ TypeReference because Jackson has something similar which I use in converters, but couldn’t find any appropriate TypeReference to use here.

Once I fix ths, usage would be:

```auto
pf.match()
    .field( Field.USER_ROLES.getFieldName() ) // -> "roles"
    .matching( userRole )
    .toPredicate();

```

Is there a chance this solutio might work? Or I missed it in total?

Thanks!

P.S. Just for the record, another question of mine from the past, with similar theme:

> [@PropertyBinder to create additional Lucene field](https://discourse.hibernate.org/t/propertybinder-to-create-additional-lucene-field/7141/3):
>
> Yes that’s one solution. If you want to use only one annotation, you can do this instead: // NOTE: this is a binder, not a bridge. class ImportanceBinder implements PropertyBinder { @Override public void bind(PropertyBindingContext context) { // This bridge is applied to properties of enum type, and that type is immutable. // Thus we don't need to declare precise dependencies. context.dependencies().useRootOnly(); context.bridge(Importance.class, new ImportancePropertyBridge( …

Here is the converter just to provide all the information.

```java
public class UserRolesConverter
        implements
            AttributeConverter< Set<UserRole>, String >,
            Serializable
{

    public static final TypeReference< Set<UserRole> > TYPE_REFERENCE = 
        new TypeReference<>() {
          //
        };

	@Override
	public String convertToDatabaseColumn( 
		final Set<UserRole> attribute 
	) {
		if (attribute == null || attribute.isEmpty()) {
			return null;
		}
		try {
			return 
				JacksonUtil.OBJECT_WRITER
					.writeValueAsString( attribute );
		}
		catch( final JsonProcessingException e ) {
			return null;
		}
	}

	@Override
	public Set<UserRole> convertToEntityAttribute( 
		final String dbData 
	) {

		if( dbData == null ) {
			return Collections.emptySet();
		}

		try {
			return 
				JacksonUtil.OBJECT_READER
					.forType( TYPE_REFERENCE )
					.readValue( dbData );
		}
		catch( final JsonProcessingException e ) {
			throw new IllegalStateException(
				"JsonProcessingException: " + e.getMessage()
			);
		}

	}

}

```

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [March 27, 2026, 2:29pm UTC](https://discourse.hibernate.org/t/searching-through-enum-set/12194/2 "2026-03-27T14:29:31Z")

</div>

Maybe I’m missing something, but, uh… Why didn’t you simply go with this?

```auto
@Column( columnDefinition = "TEXT" )
@Convert( converter = UserRolesConverter.class )
//	@Enumerated(EnumType.STRING)
@KeywordField
private Set<UserRole> roles;

```

See:

> **[10.5.4. Supported property types - Hibernate Search 8.3.0.Final: Reference...](https://docs.hibernate.org/search/8.3/reference/en-US/html_single/#mapping-directfieldmapping-supported-types)**
>
> Below is a table listing all types with built-in value bridges, i.e. property types that are supported out of the box when mapping a property to an index field. | Hibernate Search, full text search for your entities - Reference Documentation

> **[10.7. Mapping container types with container extractors - Hibernate Search...](https://docs.hibernate.org/search/8.3/reference/en-US/html_single/#mapper-orm-containerextractor)**
>
> Most built-in annotations applied to properties will work transparently when applied to container types: | Hibernate Search, full text search for your entities - Reference Documentation

I suppose you’re trying to achieve something different? What?

---

<div class="post-metadata">

**Author:** ![horvoje](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/horvoje/32/779_2.png) [@horvoje](https://discourse.hibernate.org/u/horvoje)\
**Post date:** [March 27, 2026, 4:29pm UTC](https://discourse.hibernate.org/t/searching-through-enum-set/12194/3 "2026-03-27T16:29:26Z")

</div>

Yes, that fixed it. What to say, I’m not feeling smart right now. 🤣

Thanks a million!
