休眠搜索 4.5 Alpha 1 无法在 java.lang.Byte 中猜测 FieldBridge 中的 id



我在将 EAR 项目部署到 Wildfly 8 beta1 时遇到问题。该项目使用Hibernate搜索4.5 Alpha 1。有一些实体已编制索引。项目构建良好,但在部署时会抛出异常:无法在 java.lang.Byte 中猜测 FieldBridge 中的 id。我尝试禁用所有休眠搜索注释,但仍然出现异常。接缝是一个错误。有什么建议吗?

at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:169) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_25]
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:463) [wildfly-security-manager-1.0.0.Beta3.jar:1.0.0.Beta3]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:178) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_25]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_25]
at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
Caused by: org.hibernate.search.SearchException: HSEARCH000135: Unable to guess FieldBridge for id in java.lang.Byte
at org.hibernate.search.bridge.impl.BridgeFactory.guessType(BridgeFactory.java:432)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.checkDocumentId(AnnotationMetadataProvider.java:159)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeMemberLevelAnnotations(AnnotationMetadataProvider.java:625)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass(AnnotationMetadataProvider.java:324)
at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor(AnnotationMetadataProvider.java:118)
at org.hibernate.search.engine.spi.AbstractDocumentBuilder.<init>(AbstractDocumentBuilder.java:100)
at org.hibernate.search.engine.spi.DocumentBuilderContainedEntity.<init>(DocumentBuilderContainedEntity.java:62)
at org.hibernate.search.spi.SearchFactoryBuilder.initDocumentBuilders(SearchFactoryBuilder.java:342)
at org.hibernate.search.spi.SearchFactoryBuilder.buildNewSearchFactory(SearchFactoryBuilder.java:217)
at org.hibernate.search.spi.SearchFactoryBuilder.buildSearchFactory(SearchFactoryBuilder.java:141)
at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:74)
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:52)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:581)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1837)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:854)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:847)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:396)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:846)
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:151) [wildfly-jpa-8.0.0.Beta1.jar:8.0.0.Beta1]
... 8 more

以下是重现异常的实体示例:

@Entity
@Table(name = "flow")
public class Flow implements java.io.Serializable {
private static final long serialVersionUID = 3556704047257784867L;
private Byte id;
private String name;
private String description;
public Flow() {
}
public Flow(String name) {
    this.name = name;
}
public Flow(String name, String description) {
    this.name = name;
    this.description = description;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Byte getId() {
    return this.id;
}
public void setId(Byte id) {
    this.id = id;
}
@Column(name = "name", nullable = false, length = 60)
@NotNull
@Length(max = 60)
public String getName() {
    return this.name;
}
public void setName(String name) {
    this.name = name;
}
@Column(name = "description", length = 400)
@Length(max = 400)
public String getDescription() {
    return this.description;
}
public void setDescription(String description) {
    this.description = description;
}

}

如果 id 从字节更改为短,则工作正常。字节没有内置桥。也许这是相关的,但主要问题是如果我没有休眠搜索注释,为什么休眠搜索会寻找桥接?

一个快速的解决方法 - 可以创建一个字节桥:

public class ByteBridge extends NumberBridge implements Serializable {
public Object stringToObject(String stringValue) {
    if ( StringHelper.isEmpty( stringValue ) ) return null;
    return Byte.valueOf( stringValue );
}
} 

然后向实体添加注释:

@FieldBridge(impl=....)

我尝试了自定义的FieldBridge路由,但结果是Hibernate搜索在馈送到FieldBridge之前将字节字段转换为整数对象。这意味着只需添加普通的整数桥就可以解决此问题:

@FieldBridge(impl = IntegerBridge.class)

相关内容

  • 没有找到相关文章

最新更新