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

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

user7466
1#
user7466 Published in September 20, 2018, 12:45 pm

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?

share|improve this question
  • how you are verifying that FetchType.Lazy is fetch data? – Nidhi257 Feb 12 at 4:13
  • is it possible that you have some sort of internal implementation which requires hibernate to fetch the other entity despite it being lazy ? i remember we had issues like this when using lazy fetches, where the 'laziness' of attribute entities was only ensured for instances of the encapsulating entities which made no referencing during runtime to the internal lazy entities...... – Rann Lifshitz Feb 12 at 4:20
  • @Embeddable@Table ...is maybe wished & possible, but i encounter this for the first time .... and @DiscriminatorColumn is (as per hibernate user guide) to be combined with @Inheritance... – xerx593 Feb 12 at 4:56

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO