2016-06-09 36 views
0

我使用Wildfly 10 Hibernate和我觀察到,懶@ManyToOne獲取被忽略。Wildfly 10 Hibernate延遲取不工作

@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後看到用戶的查詢。

在服務器啓動時我看到下面的logentry:

22:54:16,113 INFO [org.hibernate.tuple.entity.EntityMetamodel] (ServerService Thread Pool -- 58) HHH000157: Lazy property fetching available for: model.Storytitle 

所以日誌行說,字節碼儀器工作正常。任何想法我可以檢查什麼?我在這堂課沒有最後的修飾語。

最好的問候, 米

回答

1

我發現這個問題。

此設置在我的persistence.xml搞砸延遲抓取:

<property name="hibernate.ejb.use_class_enhancer" value="true"/>

刪除它工作正常後。