Skip to content
Advertisement

@IndexedEmbedded on class containing other @IndexedEmbedded fields

I’m trying to manage hibernate search indexing on a class with a field mapped by @IndexedEmbedded on a custom @Embeddable entity. This entity also contains others @IndexedEmbedded fields in the @MappedSuperclass. These are the entities involved:

JavaScript

And these classes:

JavaScript
JavaScript

When running the application, Hibernate Search throws the following error:

JavaScript

I’m running it with the following dependencies:

enter image description here

Any suggestion on how to manage this scenario?

Advertisement

Answer

This code is incorrect:

JavaScript

With @GenericField, you are asking Hibernate Search to generate a “value” field (string, integer, …) for languages. This generally won’t work, because Hibernate Search doesn’t know how to convert a Language into a string/integer/…, so that’s a first problem.

But the second problem, and the one being reported by Hibernate Search, is that by also putting @IndexedEmbedded on the same property, you are also asking Hibernate Search to generate an “object” (composite) field, with the same name as the “value” field from @GenericField. So there’s a conflict: both the “value” field and the “object” field have the same name, “languages”.

You should remove @GenericField wherever you use @IndexedEmbedded.


Note that technically, you could use both @GenericField and @IndexedEmbedded on the same property, as long as you explicitly set a different name on either annotation using @GenericField(name = ...) or @IndexedEmbedded(name = ...). But @GenericField would not work unless you use a custom value bridge, and I don’t think your intention was to do that anyway. So please don’t do that unless you have an actual reason and @IndexedEmbedded does not do what you want.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement