Hibernate @ManyToOne optional=true fetches parent in a separate select with FetchType.LAZY

匆匆过客 提交于 2019-12-12 02:14:18

问题


Hibernate optional @ManyToOne relationship still fetches the Parent in a separate select optional=true and fetch=FetchType.Lazy

Child

@ManyToOne //may not exist
@JoinColumns({
        @JoinColumn(name="parent_key1", insertable=false, updatable=false),
        @JoinColumn(name="parent_key2", insertable=false, updatable=false)
    })
    Parent parent

Note, that I can have a value for parent_key1, parent_key2 columns existing in Child table but a corresponding Parent need not exist with this key, that's why the optional.

These are not final classes and any select on Child is fetching Parent again in a separate select with or without LEFT JOIN FETCH suggesting optional=true and lazy do not work.

Can Parent be lazy without compile time instrumentation using @OneToOne?

来源:https://stackoverflow.com/questions/8351910/hibernate-manytoone-optional-true-fetches-parent-in-a-separate-select-with-fetc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!