我有一個在舊 .hbm.xml 文件中建模的表。檢索行的遺留代碼使用 org.hibernate.Criteria 來獲取 uniqueResult()。在遷移到 Hibernate 5.x 時,Criteria 已被棄用,因此我嘗試使用 CriteriaBuilder 來實現相同的目的。但是,當我嘗試基于之前有效的內容 (Hib 4.x) 添加限制 (Hib 5.x) 時,我收到 IllegalArgumentException:java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [xyzKey.plantName] on this ManagedType [com.foo.bar.Plant]
at org.hibernate.metamodel.model.domain.internal.AbstractManagedType.checkNotNull(AbstractManagedType.java:147)
at org.hibernate.metamodel.model.domain.internal.AbstractManagedType.getAttribute(AbstractManagedType.java:118)
at org.hibernate.metamodel.model.domain.internal.AbstractManagedType.getAttribute(AbstractManagedType.java:43)
at org.hibernate.query.criteria.internal.path.AbstractFromImpl.locateAttributeInternal(AbstractFromImpl.java:111)
at org.hibernate.query.criteria.internal.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:204)
at org.hibernate.query.criteria.internal.path.AbstractPathImpl.get(AbstractPathImpl.java:177)植物.hbm.xml:<hibernate-mapping> <class lazy="false" name="com.foo.bar.Plant" table="Plant"> <meta inherit="false" attribute="extends">com.foo.bar.PlantBase</meta> <id name="id" type="integer" column="plantID" unsaved-value="null"> <meta inherit="false" attribute="scope-set">protected</meta> <generator class="native" /> </id> <component name="xyzKey" class="com.foo.bar.PlantKey"> <meta inherit="false" attribute="use-in-tostring">true</meta> <property name="plantName" type="string" index="xyzKeyndx" unique-key="plantKey"> <column name="plantName" /> </class></hibernate-mapping>
1 回答

LEATH
TA貢獻1936條經驗 獲得超7個贊
你試過了嗎
criteriaBuilder.equal(root.get("xyzKey").get("plantName"), xyzKey.getPlantName())
添加回答
舉報
0/150
提交
取消