mkuff
mkuff

Reputation: 1682

Wildfly 10 Hibernate Lazy Fetch not working

I am using Wildfly 10 with hibernate and I observed that Lazy Fetches on @ManyToOne are ignored.

@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>

When I do a simple em.find(Storytitle.class, 1L); I see the query for the user after it loads the Storytitle.

On server startup I see the following logentry:

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

So the log line says the bytecode instrumentation is working. Any Ideas what I could check? I have no final modifiers in this class.

best regards, m

Upvotes: 0

Views: 610

Answers (1)

mkuff
mkuff

Reputation: 1682

I found the problem.

This setting in my persistence.xml messed up the lazy fetching:

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

After removing it works fine.

Upvotes: 1

Related Questions