nl.msw.compraventa.exceptions.SearchException: org.hibernate.search.SearchException: Unable to find field role.label in nl.msw.project.model.user.Usor

Hibernate JIRA | Marc Schipperheyn | 3 years ago
  1. 0

    I just tried upgrading everything to the latest version and I ran into this blocker {code} FullTextSession fts = Search.getFullTextSession(getSessionFactory().getCurrentSession()); QueryBuilder qb = fts.getSearchFactory().buildQueryBuilder().forEntity(Usor.class).get(); return (Long) fts.createFullTextQuery(qb.bool() .must( qb.keyword().onField("site.id").ignoreAnalyzer().matching(countrySite.getSite().getId()).createQuery() ) .must( qb.keyword().onField("location.country.countryCode").ignoreAnalyzer().matching(countrySite.getCountry().getCountryCode()).createQuery() ) .must( qb.keyword().onField("role.label").ignoreAnalyzer().matching(UserRole.ROLE_COUNTRYLEADER).createQuery() ).createQuery() ) .setProjection("id") .setResultTransformer(new ProjectionFirstResultTransformer()) .setCacheable(true) .setCacheRegion(CacheRegion.NEVERCHANGE) .uniqueResult(); {code} {noformat} nl.msw.compraventa.exceptions.SearchException: org.hibernate.search.SearchException: Unable to find field role.label in nl.msw.project.model.user.Usor at nl.msw.project.dao.hibernate.SearchFacetDaoHibernate.findUsersByFacet(SearchFacetDaoHibernate.java:702) [...] Caused by: org.hibernate.search.SearchException: Unable to find field role.label in nl.msw.project.model.user.Usor at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.objectToString(DocumentBuilderIndexedEntity.java:681) at org.hibernate.search.query.dsl.impl.FieldContext.objectToString(FieldContext.java:86) at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.buildSearchTerm(ConnectedMultiFieldsTermQueryBuilder.java:146) at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:100) at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:81) {noformat} Needless to say, this worked in the past. Here's the configuration for the classes in question: {code:title=Usor} @Entity(name = "User2") @Table(name = "User") @org.hibernate.annotations.Table(appliesTo = "User", indexes={ @org.hibernate.annotations.Index(name="passwd",columnNames={"email","password"}) }) @Indexed @FullTextFilterDefs({ @FullTextFilterDef(name="wallFilter",impl=HibernateWallFilterFactory.class) }) @AnalyzerDef(name = "userAnalyzer", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), filters = { @TokenFilterDef(factory = StandardFilterFactory.class), @TokenFilterDef(factory = ASCIIFoldingFilterFactory.class), @TokenFilterDef(factory = LowerCaseFilterFactory.class) }) @NaturalIdCache(region=CacheRegion.NATURAL) @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.USER) public class Usor{ @ManyToMany(cascade=CascadeType.MERGE,fetch = FetchType.LAZY) @JoinTable(name = "User_UserRoles", joinColumns = @JoinColumn(nullable = false), inverseJoinColumns = @JoinColumn(nullable = false)) @Fetch(FetchMode.SUBSELECT) @BatchSize(size=10) @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.USER) @IndexedEmbedded(prefix="role.") @JsonIgnore public Set<UserRole> getRoles() { return roles; } {code} {code:title=UserRole} @Entity @Immutable @Table(name="UserRole") @NaturalIdCache(region=CacheRegion.NATURAL) @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE,region=CacheRegion.USER) public class UserRole implements Comparable<UserRole>, Serializable,GrantedAuthority, IEntity{ @Column(length=30,nullable=false,unique=true,updatable=false) @NaturalId @Index(name="idxRoleLabel") @Field(index=org.hibernate.search.annotations.Index.YES,store=Store.YES,analyze=Analyze.NO) public String getLabel() { return label; } {code}

    Hibernate JIRA | 3 years ago | Marc Schipperheyn
    nl.msw.compraventa.exceptions.SearchException: org.hibernate.search.SearchException: Unable to find field role.label in nl.msw.project.model.user.Usor
  2. 0

    I just tried upgrading everything to the latest version and I ran into this blocker {code} FullTextSession fts = Search.getFullTextSession(getSessionFactory().getCurrentSession()); QueryBuilder qb = fts.getSearchFactory().buildQueryBuilder().forEntity(Usor.class).get(); return (Long) fts.createFullTextQuery(qb.bool() .must( qb.keyword().onField("site.id").ignoreAnalyzer().matching(countrySite.getSite().getId()).createQuery() ) .must( qb.keyword().onField("location.country.countryCode").ignoreAnalyzer().matching(countrySite.getCountry().getCountryCode()).createQuery() ) .must( qb.keyword().onField("role.label").ignoreAnalyzer().matching(UserRole.ROLE_COUNTRYLEADER).createQuery() ).createQuery() ) .setProjection("id") .setResultTransformer(new ProjectionFirstResultTransformer()) .setCacheable(true) .setCacheRegion(CacheRegion.NEVERCHANGE) .uniqueResult(); {code} {noformat} nl.msw.compraventa.exceptions.SearchException: org.hibernate.search.SearchException: Unable to find field role.label in nl.msw.project.model.user.Usor at nl.msw.project.dao.hibernate.SearchFacetDaoHibernate.findUsersByFacet(SearchFacetDaoHibernate.java:702) [...] Caused by: org.hibernate.search.SearchException: Unable to find field role.label in nl.msw.project.model.user.Usor at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.objectToString(DocumentBuilderIndexedEntity.java:681) at org.hibernate.search.query.dsl.impl.FieldContext.objectToString(FieldContext.java:86) at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.buildSearchTerm(ConnectedMultiFieldsTermQueryBuilder.java:146) at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:100) at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:81) {noformat} Needless to say, this worked in the past. Here's the configuration for the classes in question: {code:title=Usor} @Entity(name = "User2") @Table(name = "User") @org.hibernate.annotations.Table(appliesTo = "User", indexes={ @org.hibernate.annotations.Index(name="passwd",columnNames={"email","password"}) }) @Indexed @FullTextFilterDefs({ @FullTextFilterDef(name="wallFilter",impl=HibernateWallFilterFactory.class) }) @AnalyzerDef(name = "userAnalyzer", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), filters = { @TokenFilterDef(factory = StandardFilterFactory.class), @TokenFilterDef(factory = ASCIIFoldingFilterFactory.class), @TokenFilterDef(factory = LowerCaseFilterFactory.class) }) @NaturalIdCache(region=CacheRegion.NATURAL) @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.USER) public class Usor{ @ManyToMany(cascade=CascadeType.MERGE,fetch = FetchType.LAZY) @JoinTable(name = "User_UserRoles", joinColumns = @JoinColumn(nullable = false), inverseJoinColumns = @JoinColumn(nullable = false)) @Fetch(FetchMode.SUBSELECT) @BatchSize(size=10) @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.USER) @IndexedEmbedded(prefix="role.") @JsonIgnore public Set<UserRole> getRoles() { return roles; } {code} {code:title=UserRole} @Entity @Immutable @Table(name="UserRole") @NaturalIdCache(region=CacheRegion.NATURAL) @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE,region=CacheRegion.USER) public class UserRole implements Comparable<UserRole>, Serializable,GrantedAuthority, IEntity{ @Column(length=30,nullable=false,unique=true,updatable=false) @NaturalId @Index(name="idxRoleLabel") @Field(index=org.hibernate.search.annotations.Index.YES,store=Store.YES,analyze=Analyze.NO) public String getLabel() { return label; } {code}

    Hibernate JIRA | 3 years ago | Marc Schipperheyn
    nl.msw.compraventa.exceptions.SearchException: org.hibernate.search.SearchException: Unable to find field role.label in nl.msw.project.model.user.Usor

    Root Cause Analysis

    1. nl.msw.compraventa.exceptions.SearchException

      org.hibernate.search.SearchException: Unable to find field role.label in nl.msw.project.model.user.Usor

      at nl.msw.project.dao.hibernate.SearchFacetDaoHibernate.findUsersByFacet()
    2. nl.msw.project
      SearchFacetDaoHibernate.findUsersByFacet
      1. nl.msw.project.dao.hibernate.SearchFacetDaoHibernate.findUsersByFacet(SearchFacetDaoHibernate.java:702)
      1 frame