![](/img/trans.png)
[英]Hibernate @OneToOne(fetch = FetchType.LAZY) is not working
[英]Wildfly 10 Hibernate Lazy Fetch not working
我將Wildfly 10與休眠模式一起使用,並且觀察到@ManyToOne上的Lazy Fetches被忽略。
@Entity
@Table(name = "storytitles")
public class Storytitle implements Serializable {
@Id
private Long sid;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "activator_uid")
private User user;
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="services">
<jta-data-source>java:/jdbc/ds</jta-data-source>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL82Dialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.ejb.use_class_enhancer" value="true"/>
</properties>
</persistence-unit>
</persistence>
當我做一個簡單的em.find(Storytitle.class,1L); 加載Storytitle后,我看到了該用戶的查詢。
在服務器啟動時,我看到以下登錄信息:
22:54:16,113 INFO [org.hibernate.tuple.entity.EntityMetamodel] (ServerService Thread Pool -- 58) HHH000157: Lazy property fetching available for: model.Storytitle
因此,日志行顯示字節碼檢測正在運行。 有什么想法我可以檢查嗎? 我在這堂課沒有最終修飾符。
最好的問候,m
我發現了問題。
我的persistence.xml中的此設置搞亂了延遲獲取:
<property name="hibernate.ejb.use_class_enhancer" value="true"/>
刪除后,它可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.