我正在尝试将我们项目的 Hibernate 版本从4.3升级到5.2。我已经通过以下文档完成了升级所需的步骤
以及其他版本的升级文档。但是,在进行所需的更改后,我面临一些运行时错误。
我采用了一个非常简单的示例模型,在我的 EntityModel 中如下所示:
EntityMetamodel(cemployees_create:[Attribute(name=LastName, type=string [non-identifier]),Attribute(name=FirstName, type=string [non-identifier]),Attribute(name=BirthDate, type=timestamp [non-identifier] ]),Attribute(name=HireDate, type=timestamp [non-identifier]),Attribute(name=Photo, type=binary [non-identifier]),Attribute(name=ReportsTo, type=cemployees_create [non-identifier,association ]),Attribute(name=ReporteesArr, type=java.util.Collection(cemployees_create.ReporteesArr) [non-identifier,association])])
但是在5.2版中,当它试图在 AttributeFactory.java 中构建属性时,它会抛出以下异常:
java.lang.IllegalArgumentException: Expecting collection type [org.hibernate.type.BagType]
at org.hibernate.metamodel.internal.AttributeFactory.determineCollectionType(AttributeFactory.java:937)
at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:786)
at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:767)
at org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:548)
at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:77)
at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:213)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:220)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:297)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
当它试图为 Attribute(name=ReporteesArr, type=java.util.Collection(cemployees_create.ReporteesArr) [non-identifier,association])])构建属性时,就会发生这种情况
只是想检查是否有人以前遇到过这个问题,或者是否有任何解决方案。同样的事情在 Hibernate 4.3 上也能正常工作
同时添加休眠实体映射文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cfsuite.orm.manual.relationship.self_join">
<class entity-name="cemployees" table="Employees">
<tuplizer class="coldfusion.orm.hibernate.CFCTuplizer" entity-mode="dynamic-map"/>
<id column="EmployeeID" name="EmployeeID" type="integer">
<generator class="native"/>
</id>
<property column="LastName" name="LastName" type="string"/>
<property column="FirstName" name="FirstName" type="string"/>
<property column="Title" name="Title" type="string"/>
<property column="TitleOfCourtesy" name="TitleOfCourtesy" type="string"/>
<property column="BirthDate" name="BirthDate" type="date"/>
<property column="HireDate" name="HireDate" type="date"/>
<property column="Address" name="Address" type="string"/>
<property column="City" name="City" type="string"/>
<property column="Region" name="Region" type="string"/>
<property column="PostalCode" name="PostalCode" type="string"/>
<property column="Country" name="Country" type="string"/>
<property column="HomePhone" name="HomePhone" type="string"/>
<property column="Extension" name="Extension" type="string"/>
<property column="Photo" name="Photo" type="binary"/>
<property column="Notes" name="Notes" type="string"/>
<many-to-one column="ReportsTo" entity-name="cemployees" name="ReportsToObj"/>
<property column="PhotoPath" name="PhotoPath" type="string"/>
<bag cascade="all-delete-orphan" name="ReporteesArr">
<key column="ReportsTo"/>
<one-to-many entity-name="cemployees"/>
</bag>
</class>
</hibernate-mapping>