[hibernate-dev] FetchMode.SELECT

Gail Badner <[email protected]>
Newsgroups gmane.comp.java.hibernate.devel
Message-ID <CAFDzhiTe3LKNpjmPXCGDpz-ZjGs7iSXNvpHvzGJjdoCVaQpAug@mail.gmail.com>
Should it be possible to force an eager association to be loaded by a
separate query using @Fetch(FetchMode.SELECT)?

I thought that Hibernate supported that for an EAGER association, but I see
the documentation for FetchMode.SELECT
<https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#fetching-fetch-annotation>
says:

"SELECT
The association is going to be fetched lazily using a secondary select for
each individual entity, collection, or join load. It’s equivalent to
JPA FetchType.LAZY fetching strategy."

The reason I ask is because I am trying to wrap up HHH-13085, which will
change derived IDs mapped as a one-to-one association, currently loaded by
a separate query, to instead be loaded in the same query that loads the
dependent entity. I want to ensure that it is possible to revert back to
loading that one-to-one association in a separate query after HHH-13085 is
fixed.

Currently, a StackOverflowError is thrown when loading an entity with an ID
that is an bidirectional eager one-to-one association has FetchMode.SELECT
mapped.

@Entity(name = "Foo")public class Foo implements Serializable {

    @Id
    @GeneratedValue
    private Long id;

    @OneToOne(mappedBy = "foo", cascade = CascadeType.ALL)
    private Bar bar;
}

@Entity(name = "Bar")public class Bar implements Serializable {
@Id
    @OneToOne(fetch = FetchType.EAGER)
    @Fetch(FetchMode.SELECT)
    @JoinColumn(name = "BAR_ID")
    private Foo foo;
}


According to the documentation, it sounds like @Fetch(FetchMode.SELECT)
should make the association lazy. Is that really correct?

Could someone please clarify the expected behavior?

I created HHH-14390 <https://hibernate.atlassian.net/browse/HHH-14390> for
the StackOverflowError. I've pushed some FailureExpected tests
<https://github.com/hibernate/hibernate-orm/commit/b40d1251e385a5fdb018f9583a83c472d6da4e8f>
that reproduce this issue.

Thanks,
Gail
_______________________________________________
hibernate-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.