Home @ManyToOne(fetch=FetchType.LAZY, optional=false) still fetching
Reply: 1

@ManyToOne(fetch=FetchType.LAZY, optional=false) still fetching

user1589188
1#
user1589188 Published in 2018-02-12 04:11:13Z

I have an @Embeddable class:

@Embeddable
@Table(name="MY_TABLE")
public class MyTable {
    @ManyToOne(fetch=FetchType.LAZY, optional=false)
    @JoinColumn(name="my_other_id")
    private MyOtherEntity myOtherEntity;
    ...
}

@Entity
@Table(name="MY_OTHER_TABLE")
@DiscriminatorColumn(name="DISC", discriminatorType=DiscriminatorType.STRING)
public abstract class MyOtherEntity {
    ...
}

@Entity
@DiscriminatorValue("A")
public class MyOtherEntityA extends MyOtherEntity {
    ...
}

@Entity
@DiscriminatorValue("B")
public class MyOtherEntityB extends MyOtherEntity {
    ...
}

As with the LAZY fetch type, I would expect MyOtherEntity to be a proxy only, not the actual class initialised. But Hibernate is still issuing a query to fetch all its columns (except those further marked as LAZY within MyOtherEntity) once the owner class of MyTable calls getMyTable().

Adding optional=false as suggested in Hibernate: one-to-one lazy loading, optional = false and Hibernate ManyToOne FetchType.LAZY is not working? did not help. And the class is not final as suggested in Hibernate ManyToOne with FetchType.LAZY not fetching lazy . Any other reason how LAZY is not working as expected?

Sibin cms
2#
Sibin cms Reply to 2018-02-12 04:30:40Z

specify @Proxy(lazy=true)

@Proxy(lazy=true) 
@Embeddable
@Table(name="MY_TABLE")
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.321625 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO