我在向Wildfly 8 beta1部署EAR项目时遇到问题。该项目使用Hibernate Search 4.5 Alpha 1.索引了一些实体。该项目构建正常,但在部署时会抛出异常:无法在java.lang.Byte中猜测FieldBridge的id。我尝试禁用所有hibernate搜索注释,但仍会出现异常。接缝是一个bug。有什么建议吗?
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从Byte更改为Short,则工作正常。 Byte没有内置桥接器。也许这是相关的,但主要问题是如果我没有hibernate搜索注释,为什么hibernate搜索正在寻找桥接器?
答案 0 :(得分:1)
快速解决方法 - 可以创建ByteBridge:
public class ByteBridge extends NumberBridge implements Serializable {
public Object stringToObject(String stringValue) {
if ( StringHelper.isEmpty( stringValue ) ) return null;
return Byte.valueOf( stringValue );
}
}
然后向实体添加注释:
@FieldBridge(impl=....)
答案 1 :(得分:1)
我尝试了自定义FieldBridge路由,但事实证明Hibernate Search在将字节字段转换为Integer对象之前将其提供给FieldBridge。这意味着只需添加正常的IntegerBridge即可解决问题:
@FieldBridge(impl = IntegerBridge.class)