亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Hibernate 5.x 遷移 Criteria 到 CriteriaBuilder

Hibernate 5.x 遷移 Criteria 到 CriteriaBuilder

MM們 2023-09-20 16:33:10
我有一個在舊 .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())


查看完整回答
反對 回復 2023-09-20
  • 1 回答
  • 0 關注
  • 105 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號